FORMATNUMBER function
Number
The number to format.
MinimumNumberOfDecimalPlaces
The minimum number of decimal places a number should be formatted with. Must be greater than or equal to 0 and less than or equal to the maximum number of decimal places. If omitted, 2 is assumed.
MaximumNumberOfDecimalPlaces
The maximum number of decimal places a number should be formatted with. Must be greater than or equal to the minimum number of decimal places. If omitted, this parameter is set to the minimum number of decimal places.
OmitThousandsSeparators
FALSE to include thousands separators and TRUE to exclude them. If omitted, FALSE is assumed.
MinimumNumberOfIntegerDigits
The minimum number of digits the integer part should be formatted with. If this parameter is greater than the number of digits of the integer part, it is padded with zeroes, meaning that 123 formatted with a minimum of five integer digits is rendered as "00123." If omitted, one is assumed.
UseAccountingStyle
Whether negative numbers should be enclosed in parentheses instead of being preceded with a minus sign. If omitted, FALSE is assumed.
LeadingUnit
The leading unit that should precede the returned formatted number.
TrailingUnit
The trailing unit that should follow the returned formatted number.
Returns
A formatted textual representation of a number.
Returns a number as text. FORMATNUMBER(1003.75)FORMATNUMBER(1003,75) returns "1,003.75" if the language of the app is set to US English and "1 003,75" if the language is set to German.
FORMATNUMBER takes the language of the app into account when converting numbers. For instance, a decimal point is used when the language is set to US English and a decimal comma is used when the language is set to French.
This function is specific to Calcapp.
Decimal places
The second and third parameters are used to control the number of decimal places the number is formatted with. If only the second parameter is given, it specifies the exact number of decimal places that are used.
This formula returns "1,003.7500", using exactly four decimal places:
If a third parameter is given, the second parameter is interpreted as the minimum number of decimal places that should be used and the third parameter is interpreted as the maximum number of decimal places that should be used.
This formula uses between 2 and 6 decimal places:
As 1003 is an integer and no decimal places are required, "1,003.00" is returned (for US English).
This formula returns "1,003.123457", because a maximum of six decimal places may be used:
Thousands separators
The fourth parameter may be set to TRUE to prevent thousands separators from being used. This formula returns "1024.82" (for an app set to US English), and not "1,024.82":
Padding the number with leading zeroes
The fifth parameter, MinimumNumberOfIntegerDigits
, pads the
number with leading zeroes, if necessary. This formula returns "0003.75":
Accounting style
The sixth parameter, UseAccountingStyle
, comes into play when
formatting negative numbers. In some languages, accounting style means that
negative numbers — denoting a currency amount — are formatted using
parentheses.
Consider this formula:
If the app is set to use UK English, the formula above returns "(23.00)". This convention isn't used in German and many other languages, meaning that if the app is set to German, "-23,00" is returned.
Leading and trailing units
The remaining parameters, LeadingUnit
and
TrailingUnit
, are used to specify units. "$" or "€" can be used
as leading units, for instance, and " lbs", " kg" and the like can
be used as trailing units.
Consider this formula:
For an app set to use US English app, the formula above returns "$23.00". If the first parameter is set to -23-23 instead, "($23.00)" is returned.
Named parameters
When a large number of parameters are provided to FORMATNUMBER, it can be
hard to keep track of which values go with which parameters. To make this
easier, a parameter name, followed by :
, may precede its value.
These formulas are equivalent:
All parameters don't need to be named, but once a parameter has been named, the remaining parameters must also be named.
Named parameters make it possible to provide parameters out-of-order and to omit optional parameters that normally would have been expected to precede a parameter, had it not been named. Omitted optional parameters use default values.
The formula above uses default values for all parameters other than
Number
and LeadingUnit
. As such, those optional
parameters can be removed from the formula:
Use named parameters when they help make a formula easier to read.
Related functions
- Use FORMATFRACTION to format fractions (0.75 can be formatted as "3/4").
- Use FORMATPERCENTAGE to format percentages (0.75 can be formatted as "75%").
- Use FORMATSCIENTIFIC to use scientific notation (1,500 can be formatted as "1.5E+03").
- Use FIXED to round a number to the left of the decimal separator (7,523 can be formatted as "7,500").
- Use PARSENUMBER to turn the text returned from this function back into a number.
Examples
Returns a formatted version of the value of Field1, using the default settings of FORMATNUMBER (two decimal places are used as well as thousands separators).
Returns a formatted version of the value of Field1, using the formatting settings of Field1.
Returns "1,003.75" if the language of the app is set to US English and "1 003,75" if the language is set to German.
Returns the array { "1,003.75", "0.21" }{ "1,003.75"; "0.21" } if the language of the app is set to US English. When invoked with an array, FORMATNUMBER is invoked once per array element and the results are collected in an array.
Returns "1,003.7500" if the language of the app is set to US English, using exactly four decimal places.
Returns "1,003.00" if the language of the app is set to US English. As both the second and the third parameter are specified, 2 is taken to mean the minimum number of decimal places that should be used, and 6 is taken to mean the maximum number of decimal places that should be used.
Returns "1,003.123457" if the language of the app is set to US English. As both the second and the third parameter are specified, 2 is taken to mean the minimum number of decimal places that should be used, and 6 is taken to mean the maximum number of decimal places that should be used.
Returns "1024.82" (for an app set to US English), and not "1,024.82". Thousands separators are not used.
Returns "0003.75". The minimum number of integer digits are specified (appearing before the decimal separator), which pads the number with leading zeroes, if necessary.
Returns "(23.00)", with the app language set to UK English. Here, "accounting style" is used for negative numbers. For some languages, this has the effect of enclosing the number in parentheses instead of preceding it with a minus sign.
Returns "($23.00)", with the app language set to UK English. Had the number been 23, "$23.00" would have been returned. The leading unit is set to the currency symbol "$".
Returns "23 lbs". The trailing unit is set to " lbs".