I have been programming in classic ASP for over 6 years now. When building checkout facilities it is necessary to round prices to 2 decimal places (for instance when adding VAT to a basket total).

Sadly during testing of the inbuilt ASP function “Round” I have noticed that in certain circumstances it returns an incorrect result. Below is a list of numbers rounded to 2 decimal places using the “Round” function:

Start Number: Result:
1.275 1.27
1.2755555555 1.28
1.235 1.24
1.278 1.28
1.216 1.22
1.295 1.3
1.273 1.27
1.212 1.21

The code to obtain these results was:

1.275
1.2755555555
1.235
1.278
1.216
1.295
1.273
1.212

You can see what while most are rounding correctly the first row is incorrect, 1.275 should round to 1.28 not 1.27. This problem was consistent on 2 separate Windows 2003 servers using IIS6. I have however noticed that the “formatcurrency” function works correctly in all these circumstances, because of this I wrote the following function:

function roundnum(num)
dim return
if isnumeric(num) then
return = replace(formatcurrency(num),"£","")
end if
roundnum = CDbl(return)
end function

This simply takes the number, runs it through the “formatcurrency” function and then removes the returned pound sign. The results of this on the same set of numbers are:

Start Number: Result:
1.275 1.28
1.2755555555 1.28
1.235 1.24
1.278 1.28
1.216 1.22
1.295 1.3
1.273 1.27
1.212 1.21

The code to obtain these results was:

1.275
1.2755555555
1.235
1.278
1.216
1.295
1.273
1.212