ROUND(expression [,numdecimalplaces])

Returns a number rounded to a given number of decimal places (Double).


expressionThe expression to round.
numdecimalplaces(Optional) The number of decimal places to round to (Long).

REMARKS
* This function will either round up or down depending on the last digits.
* This function can be used to round a floating-point or fixed-point decimal to a specified number of places.
* "numdecimalplaces" must be greater than or equal 0.
* If "numdecimalplaces" is left blank, then 0 is used.
* If "numdecimalplaces" is left blank, then an Integer is returned.
* If "numdecimalplaces" < 0, then you will get a run-time error 5.
* Exactly what this function rounds to when the digit is a 5 is not very predictable (add examples below).
* You can use the INT function to return the number rounded down to the nearest integer.
* The equivalent .NET function is System.Math.Round
* For the Microsoft documentation refer to docs.microsoft.com

Dim dbValue As Double 
dbValue = 0.9
Round(dbValue) = 1

dbValue = 0.9
Round(dbValue,1) = 0.9

dbValue = 0.149
Round(dbValue,2) = 0.15

dbValue = 0.169
Round(dbValue,2) = 0.17

Debug.Print Round(123.456, 0) = 123
Debug.Print Round(123.456, 1) = 123.5
Debug.Print Round(123.456, 2) = 123.46
Debug.Print Round(123.456, 3) = 123.456

Debug.Print Round(56.78, 0) = 57
Debug.Print Round(56.78, 1) = 56.8
Debug.Print Round(56.78, 2) = 56.78
Debug.Print Round(56.78, 3) = 56.78

© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited Top