I would like to round off a number to 4 decimal places
13.58386104
What I'm looking for is 13.5839
Thank you
Printable View
I would like to round off a number to 4 decimal places
13.58386104
What I'm looking for is 13.5839
Thank you
Use the VB Round function.
Hope this helps!Code:MsgBox Round(13.58386104, 4)
Later
Use the Format function too
Format(13.4582,"0.00") = 13.46
when i used round it didn't seem to round correctly with more than 2 decimal places..
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.
Hope this helps!Code:'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
Later
i had my value set to integer... thats probably why!
thanks
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.