Round Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

sngResult = 0.025
sngResult = Round(sngResult , 2)

The code above yields sngResult = 0.03. It should be 0.02 (Round function
rounds so that last digit is an even number).

Any suggestions?
 
Welcome to the wonderful world of floating point arithmetic.

Just as there are values that humans can't represent precisely using base 10
(think of fractions like one third), so too are there values that computers
can't represent precisely using base 2 (or base 16).

Take a look at the following code:

Sub Roundoff()
Dim sngResult As Single

sngResult = 0.025
Debug.Print sngResult - 0.025

End Sub

When I go to the Immediate Window (Ctrl-G) and run it, I get:

Roundoff
3.72529028458413E-10

In other words, sngResult is marginally larger than 0.025, so Round sets it
to .03

You could try using the Currency data type.
 
DevDaniel said:
sngResult = 0.025
sngResult = Round(sngResult , 2)

The code above yields sngResult = 0.03. It should be 0.02 (Round function
rounds so that last digit is an even number).

What version of Access are you using? In Access 2007, I got this:

sngResult=0.025
? sngResult
0.025
? round(sngResult,2)
0.02

Tom Lake
 
Tom Lake said:
What version of Access are you using? In Access 2007, I got this:

sngResult=0.025
? sngResult
0.025
? round(sngResult,2)
0.02

Tom Lake

I'm using Access 2003.
 
DevDaniel said:
I'm using Access 2003.

I'm using Access 2003 (SP2) as well and got 0.02. What I did notice is that
excel returns 0.03. Not sure if that might help.
 
Back
Top