Forum Discussion
Morya_ali_asiri
Jul 13, 2021Copper Contributor
Rounding decimals in a math operation
Hello When performing a arithmetic operation in an Access field, such as ((5*5*4/3)+2*5+2*4)/20=2.56 I want a code that rounds this result to 3 meaning nearest and highest integer thank you
Gustav_Brock
Jul 14, 2021Iron Contributor
... as the nearest integer could be lower, I guess you mean "nearest higher integer".
That is rounding up which is easy to perform:
ValueUp = -Int(-(5*5*4/3+2*5+2*4)/20)
' ValueUp will be 3.
For serious rounding of any values with extreme precision, go to https://github.com/GustavBrock/VBA.Round .
- isladogsJul 14, 2021MVPInteresting. So both of these expressions round up to the next higher integer for all positive and negative numbers
Int(YourNumber)+1
-Int(-YourNumber)
However if the result is itself an integer, adding 1 will give the wrong result.
So I agree that that using Gustav's method is better.
-