Be the first user to complete this post
|Add to List|
Excel-VBA: Math Functions – ROUND()
The ROUND function in MS excel returns a rounded number based on the specified number of digits.
Note : ROUND() works slightly diffrent when used as Excel formula, Click here to know about it Formula-ROUND()
As VBA Function : ROUND(number, [decimal places])
Note : If you don't provide the decimal places the function will consider it as 0 and returns the Integer.
- Type: Number
- Number which requires to be rounded.
- decimal places
- Type: Number
- Number of digits to the number to
If number you are rounding ends with 5 then this function will return the number ending with nearest even number, see example
Round(4.55,1) Output: 4.6 (round up) Round(6.85,1) Output: 6.8 (round down)
Round(3.33,0) Output: 3 Round(25.77,1) Output: 25.8 Round(37.14,1) Output: 37.1 Round(26.32) Output: 26
Function getROUND() Dim val1 Dim val2 Dim val3 Dim val4 val1 = 3.33 val2 = 8.85 val3 = 9.99 val4 = 25.787676 strResult = "The ROUND number of " & val1 & " when no argument for decimal provided " & Round(val1) & vbCrLf strResult = strResult & "The ROUND number of " & val2 & " with 1 decimal place is " & Round(val2, 1) & vbCrLf strResult = strResult & "The ROUND number of " & val3 & " with 0 decimal place is " & Round(val3, 0) & vbCrLf strResult = strResult & "The ROUND number of " & val4 & " with 2 decimal place is " & Round(val4, 2) MsgBox strResult End Function