Display Small Decimals Using VBScript

It is common to have online survey results posted via an ASP page. While for the most part it will work fine, you have to be careful when your results contain small irrational numbers. For small irrational numbers, ASP automatically returns the number in scientific notation. To avoid this result, use either the FormatPercent or the FormatNumber function. Conveniently, the FormatPercent function will multiply your result by 100. For example, this code:

 Response.Write "

" & 5 / 50025 * 100 & "%"Response.Write "

" & FormatPercent(5 / 50025, 4) '4 digits after decimal pointResponse.Write "

" & FormatNumber(5 / 50025, 4) '4 digits after decimal point

will produce:

 9.99500249875063E-03% 0.0100% 0.0001 
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: