Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Round to n decimals


'Multiply the value by a power of ten
'Round to an integer using CInt
'Divide by the power of ten.
Dim Round As Double , nDigits As Long , nValue As Double
Round = Int(nValue * (10 ^ nDigits) + 0.5) / (10 ^ nDigits)

'alterate approach
Round = Format (nValue, "0.00\0" )