Collabora Office 24.04 laguntza
Zenbakizko adierazpen bati aplikatutako zenbaki-formatua duen kate bat itzultzen du.
FormatNumber( expression As Variant, [numDigitsAfterDecimal As Integer], [includeLeadingDigit As Integer], _
[useParensForNegativeNumbers As Integer], [groupDigits As Integer] ) As String
String
expression: Required. A numeric expression to be formatted. If expression is a string, then the decimal and thousands separator need to be localized.
digituKopDezimalOndoren: Aukerakoa. Dezimalaren ondoren bistaratu behar den digitu kopurua zehazten duen zenbakizko balioa. Ez bada ezartzen, balioa -1 izango da: erabiltzaile-interfazearen eskualde-ezarpenaren balio lehenetsia erabiliko da.
includeLeadingDigit: Aukerakoa. vbTriState enumerazio-balio bat, aurretik zatikizko balioetan zero bat bistaratuko den ala ez zehazten duena.
vbTrue edo -1: Bistaratu zero bat aurretik.
vbFalse edo 0: Ez bistaratu zerorik aurretik.
vbUseDefault or -2: Use the user interface locale settings. This is the default when omitted.
useParensForNegativeNumbers: Aukerakoa. vbTriState enumerazio-balio bat, zenbaki negatiboak parentesi artean idatzi behar diren ala ez zehazten duena.
vbTrue edo -1: Erabili parentesiak zenbaki negatiboetan.
vbFalse edo 0: Ez bistaratu parentesiak.
vbUseDefault or -2: Same as vbFalse. This is the default when omitted.
groupDigits: Aukerakoa. vbTriState enumerazio-balio bat, zenbakia hizkuntza-ezarpenetan zehaztutako mugatzailearekin elkartu beharko den (milakoetan, etab.) ala ez zehazten duena.
vbTrue edo -1: Elkartu digituak.
vbFalse edo 0: Ez elkartu digituak.
vbUseDefault or -2: Same as vbFalse. This is the default when omitted.
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