FormatNumber function
Returns an expression that has been formatted as a numeric value.
FormatNumber(
expression [,NumDigitsAfterDecimal [,IncludeLeadingDigit [,UseParensForNegativeNumbers [,GroupDigits]]]]
)
Arguments
Expression
Required option. The expression to be formatted.
Numdigitsafterdecimal
Options available. A numeric value indicating the number of digits displayed to the right of the decimal point. The default value is-1, which indicates that the computer's locale is being used.
IncludeLeadingDigit
Options available. A three-state constant that indicates whether to display a decimal value of 0 in the front. For numeric values, see the "Settings" section.
UseParensForNegativeNumbers
Options available. A three-state constant that indicates whether negative values are placed in parentheses. For numeric values, see the "Settings" section.
GroupDigits
Options available. A three-state constant that indicates whether numbers are grouped by using the numeric grouping symbols specified in the computer locale. For numeric values, see the "Settings" section.
Set up
The IncludeLeadingDigit, useparensfornegativenumbers, and GroupDigits parameters can have the following values:
| Constants |
value |
Description |
| TristateTrue |
-1 |
True |
| Tristatefalse |
0 |
False |
| Tristateusedefault |
-2 |
Use the settings in your computer's regional settings. |
Description
When one or more optional arguments are omitted, the computer locale provides the value of the omitted parameter.
Note that all settings information is taken from the Number tab of the locale.
The following example uses the formatnumber function to format the numeric value as a number with a four-bit decimal point:
The Function formatnumberdemo Dim myangle, mysecant, MyNumber myangle = 1.3 ' the angle defined in radians. mysecant = 1/cos (myangle) ' calculates the secant value. Formatnumberdemo = FormatNumber ( mysecant , 4 ) ' formats mysecant as a number with four-bit decimal points. End Function