FormatCurrency, FormatNumber, FormatPercent Functions (VB6) |
No
FormatCurrency(number[,DecimalPlaces ][, _ IncLeadingZero[,UseParenthesis[,GroupDigits]]]]) FormatNumber(number[,DecimalPlaces ][, _ IncLeadingZero[,UseParenthesis[,GroupDigits]]]]) FormatPercent(number[,DecimalPlaces ][, _ IncLeadingZero[,UseParenthesis[,GroupDigits]]]])
number
Use: Required
Data Type: Any numeric expression
The number to be formatted.
DecimalPlaces
Use: Optional
Data Type: Long
Number of digits the formatted string should contain after the decimal point.
IncLeadingZero
Use: Optional
Data Type: TriState constant
Indicates if the formatted string is to have a before floating point numbers between 1 and –1.
UseParenthesis
Use: Optional
Data Type: TriState constant
Specifies whether parentheses should be placed around negative numbers.
GroupDigits
Use: Optional
Data Type: TriState constant
Determines whether digits in the returned string should be grouped using the delimiter specified in the computer's regional settings. For example, on English language systems, the value 1000000 is returned as 1,000,000 if GroupDigits is True.
String
The three functions are almost identical. They all take identical arguments, the only difference being that FormatCurrency returns a formatted number beginning with the currency symbol specified in the computer's regional settings, FormatNumber returns just the formatted number, and FormatPercent returns the formatted number followed by a percentage sign (%).
If DecimalPlaces isn't specified, the value in the computer's regional settings is used.
The Tristate constant values are TristateTrue, TristateFalse, and TriStateUseDefault.
These three functions first appeared in VBScript version 2 as "light" alternatives to the Format function, which had originally been left out of VBScript due to its size. They are quick and easy to use, and make your code more self-documenting; you can instantly see what format is being applied to a number without having to decipher the format string.