PDA

View Full Version : Round to include '0' after decimal...


parallon
08-06-2009, 10:31 PM
Hello all. Not sure what forum to include VBScript issues in, so bear with me. I was just wondering how to force the following function to append a '0' to a value that has no decimal (raminder)?

vPercent = round(((vEmpQty / vTotalCount) * 100) + .001,1)

E.g. I want 55 to be 55.0

Thanks,

Mike

Old Pedant
08-06-2009, 10:51 PM
Has nothing at all to do with the rounding.

Has to do with how you *DISPLAY* that value.

If all you do with it isResponse.Write vPercent then you *will* get whatever the default display of numbers is, by VBScript. And, yes, if a number has no value after the decimal point, then neither the decimal point nor the zero is shown.

To control the *DISPLAY* of numbers, use one of VBScripts 3 handy builtin functions:

Response.Write FormatNumber( vPercent, 1 )
Response.Write FormatPercent( vPercent, 1 )
Responce.Write FormatCurrency( someMoneyValue, 2 )

In fact, you don't *NEED* to use ROUND() here if all you are going to do is display that number:

Response.Write FormatNumber( ((vEmpQty / vTotalCount) * 100) + .001, 1 )

parallon
08-06-2009, 11:14 PM
That worked awesome. Thanks!

Mike