or if you know for a fact that you will never need a precision greater than 2 digits past the decimal, then use the CURRENCY datatype instead of double, and you will not have this problem
This will always give you the correct answer.
It’s a well known programming trick from the time I was programming in Dibol and Cobol.
(I’m getting old. ;))
[quote=97198:@Paul Sondervan]You can also do it this way.
msgbox str(format(2.15 + 0.05, "0.0"))
This will always give you the correct answer.
It’s a well known programming trick from the time I was programming in Dibol and Cobol.
(I’m getting old. ;))[/quote]
Actually, if you try “format(2.20 + 0.05, “0.0”)”, it doesn’t work. You still get 2.2.
Function RoundDblToNplaces(origNum as Double, places as Integer) As Double
dim roundedNum as double
// get adjustment value
dim s as string = “.”
For i as integer = 1 to places
s = s + “0”
Next
s = s + “5”
Dim adjustmentValue as Double = Val(s)
// get format string
Dim formatString as string = “#######.”
For i as integer = 1 to places
formatString = formatString + “0”
Next
Dim formattedNumString as String = Format(origNum + adjustmentValue, formatString)