How to Round Numbers
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 'Math - How to Round Numbers Option Explicit Function Round(nValue As Double, nDigits As Integer) As Double Round = Int(nValue * (10 ^ nDigits) + 0.5) / (10 ^ nDigits) End Function Private Sub Main() 'To round to 2 decimal places MsgBox Round(63.23892, 0) 'Display 63 'To round to 2 decimal places MsgBox Round(63.23892, 1) 'Display 63.2 'To round to 2 decimal places MsgBox Round(63.23892, 2) 'Display 63.24 'To round to 2 decimal places MsgBox Round(63.23892, 3) 'Display 63.239 'To round to 2 decimal places MsgBox Round(63.23892, 4) 'Display 63.2389 End Sub |