FormatNumber Function [VBA]
/text/sbasic/shared/03170010.xhp
FormatNumber( expression As Variant, [numDigitsAfterDecimal As Integer], [includeLeadingDigit As Integer], _
[useParensForNegativeNumbers As Integer], [groupDigits As Integer] ) As String
Sub TestFormatNumber
testName = "Test 1: positive, 2 decimals"
str2 = "12.20"
str1 = FormatNumber("12.2", 2, vbFalse, vbFalse, vbFalse)
msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2)
testName = "Test 2: negative, 20 decimals, use leading zero"
str2 = "-0.20000000000000000000"
str1 = FormatNumber("-.2", 20, vbTrue, vbFalse, vbFalse)
msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2)
testName = "Test 3: negative, 20 decimals, no leading zero"
str2 = "-.20000000000000000000"
str1 = FormatNumber("-0.2", 20, vbFalse, vbFalse, vbFalse)
msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2)
testName = "Test 4: negative, no leading zero, use parens"
str2 = "(.20)"
str1 = FormatNumber("-0.2", -1, vbFalse, vbTrue, vbFalse)
msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2)
testName = "Test 5: negative, default leading zero, use parens"
str2 = "(0.20)"
str1 = FormatNumber("-0.2", -1, vbUseDefault, vbTrue, vbFalse)
msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2)
testName = "Test 6: group digits"
str2 = "-12,345,678.00"
str1 = FormatNumber("-12345678", -1, vbUseDefault, vbUseDefault, vbTrue)
msgbox( "FormatNumber returned: " + str1 + ", Expected: " + str2)
End Sub