FormatCurrency, FormatNumber, FormatPercent Functions | |
Class Microsoft.VisualBasic.Strings Syntax Dim result As String = FormatCurrency(expression[, _ numDigitsAfterDecimal[, includeLeadingDigit[, _ useParensForNegativeNumbers[, groupDigits]]]]) Dim result As String = FormatNumber(expression[, _ numDigitsAfterDecimal[, includeLeadingDigit[, _ useParensForNegativeNumbers[, groupDigits]]]]) Dim result As String = FormatPercent(expression[, _ numDigitsAfterDecimal[, includeLeadingDigit[, _ useParensForNegativeNumbers[, groupDigits]]]]) Several parameters use the Microsoft.VisualBasic.TriState enumeration, which has the following members: Value | Description |
---|
true | Use the "true" or enabled setting. | False | Use the "false" or disabled setting. | UseDefault | Use the default regional setting for this parameter. |
expression (required; Object) The number or numeric expression to be formatted.
numDigitsAfterDecimal (optional; Integer) The number of digits the formatted string should contain after the decimal point. If omitted, 1 is used, which indicates that the default regional settings should be used.
includeLeadingDigit (optional; TriState enumeration) Indicates whether the formatted string is to have a 0 before floating point numbers between 1 and -1. If omitted, UseDefault is used.
useParensForNegativeNumbers (optional; TriState enumeration) Indicates whether parentheses should be placed around negative numbers. If omitted, UseDefault is used.
groupDigits (optional; TriState enumeration) Determines whether digits in the returned string should be grouped using the delimiter specified in the computer's regional settings. For example, in the United States region, the value 1000000 is returned as "1,000,000" if groupDigits is true. If omitted, UseDefault is used. Description The FormatCurrency, FormatNumber, and FormatPercent functions are used to format decimal numbers using common formats. FormatCurrency returns the number formatted as currency based on the regional settings; FormatNumber returns the number in a standard decimal format; and FormatPercent returns the number formatted as a percentage (first multiplying the number by 100). Usage at a Glance In the FormatCurrency function, the position of the currency symbol in relation to the currency value is defined by the computer's regional settings. 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. See Also Format Function, FormatDateTime Function |