Round Function

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?
 
D

Douglas J. Steele

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.
 
T

Tom Lake

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
 
G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

round-to-even logic 7
Rounding 2
Round up or down in .5 increments 6
Round values up and down 3
Round Function 5
Rounding help 1
Round formula 1
IF with Equal to or Greater than 4

Top