Click to See Complete Forum and Search --> : Rounding a number


Cdogg
Jan 11th, 2001, 12:18 PM
I would like to round off a number to 4 decimal places

13.58386104
What I'm looking for is 13.5839

Thank you

[Digital-X-Treme]
Jan 11th, 2001, 01:30 PM
Use the VB Round function.


MsgBox Round(13.58386104, 4)


Hope this helps!

Later

manuelromero
Jan 12th, 2001, 11:37 AM
Use the Format function too

Format(13.4582,"0.00") = 13.46

Jan 19th, 2001, 05:36 PM
when i used round it didn't seem to round correctly with more than 2 decimal places..

[Digital-X-Treme]
Jan 20th, 2001, 06:08 AM
nzer, check to make sure you are using the correct data types. For example, if you store the result of Round() in an integer or long, it will only store the number up to the decimal point. If you store the result of Round() in a Double, then it works fine.


'Rounds well. Produces 3.21212
Dim x As Double
x = Round(3.21212321334341, 5)
MsgBox x


'Doesn't work. Produces 3
Dim x As Integer
x = Round(3.21212321334341, 5)
MsgBox x


Hope this helps!

Later

Jan 20th, 2001, 06:44 PM
i had my value set to integer... thats probably why!
thanks

crutchlb
Feb 5th, 2001, 10:34 AM
Where A = 13.58386104 then

A = (Int( A * 10000 + .5)) / 10000

A = 13.5839

Additionally if you wanted to round to the nearest lowest 3 DP. then

A = (Int( A * 1000 )) / 1000

A = 13.583

Or Nearest Highest Quarter (For those who work with Imperial dimensions in engineering.)

A = (Int( A * 4 + .9999999 )) / 4

A = 13.750


You could quite easily convert all this into routines. Hope it helps.