Name
Round Function
Syntax
Round(expression[,numdecimalplaces])
-
expression Use: Required
Data Subtype: Numeric
Any numeric expression.
-
numdecimalplaces Use: Optional
Data Subtype: Long
The number of places to include after the decimal point.
Return Value
The same data subtype as expression.
Description
Rounds a given number to a specified number of decimal places.
Rules at a Glance
numdecimalplacescan be any whole number between and 16.Roundfollows standard rules for rounding:If the digit in the position to the right of
numdecimalplacesis greater than 5, the digit in thenumdecimalplacesposition is incremented by one.If the digit in the position to the right of numdecimalplaced is less than 5, the digits to the right of
numdecimalplacesare dropped.If the digit in the position to the right of
numdecimalplacesis 5 and the digit in thenumdecimalplacesposition is odd, the digit in thenumdecimalplacesposition is incremented by one.If the digit in the position to the right of
numdecimalplacesis 5 and the digit in thenumdecimalplacesposition is even, the digits to the right ofnumdecimalplacesare dropped.
Programming Tips & Gotchas
If
expressionis a string representation of a numeric value,Roundconverts it to a numeric value before rounding. However, ifexpressionisn’t a string representation of a number,Roundgenerates runtime error 13, “Type mismatch.” TheIsNumericfunction insures thatexpressionis a proper numeric representation before callingRound.If
expressioncontains ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access