FORMATNUMBER function

FORMATNUMBER(Number, MinimumNumberOfDecimalPlaces?, MaximumNumberOfDecimalPlaces?, OmitThousandsSeparators?, MinimumNumberOfIntegerDigits?, UseAccountingStyle?, LeadingUnit?, TrailingUnit?) FORMATNUMBER(Number; MinimumNumberOfDecimalPlaces?; MaximumNumberOfDecimalPlaces?; OmitThousandsSeparators?; MinimumNumberOfIntegerDigits?; UseAccountingStyle?; LeadingUnit?; TrailingUnit?)

Number

Number or { Number }

The number to format.

MinimumNumberOfDecimalPlaces

Number or { Number } (optional)

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

Number or { Number } (optional)

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

Logical or { Logical } (optional)

FALSE to include thousands separators and TRUE to exclude them. If omitted, FALSE is assumed.

MinimumNumberOfIntegerDigits

Number or { Number } (optional)

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

Logical or { Logical } (optional)

Whether negative numbers should be enclosed in parentheses instead of being preceded with a minus sign. If omitted, FALSE is assumed.

LeadingUnit

Text or { Text } (optional)

The leading unit that should precede the returned formatted number.

TrailingUnit

Text or { Text } (optional)

The trailing unit that should follow the returned formatted number.

Returns

Text or { Text }

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:

FORMATNUMBER(1003.75, 4)FORMATNUMBER(1003,75; 4)

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:

FORMATNUMBER(1003, 2, 6)FORMATNUMBER(1003; 2; 6)

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:

FORMATNUMBER(1003.123456789, 2, 6)FORMATNUMBER(1003,123456789; 2; 6)

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":

FORMATNUMBER(1024.816, 2, 2, TRUE)FORMATNUMBER(1024,816; 2; 2; TRUE)

Padding the number with leading zeroes

The fifth parameter, MinimumNumberOfIntegerDigits, pads the number with leading zeroes, if necessary. This formula returns "0003.75":

FORMATNUMBER(3.75, 2, 2, TRUE, 4)FORMATNUMBER(3,75; 2; 2; TRUE; 4)

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:

FORMATNUMBER(-23, 2, 2, TRUE, 1, TRUE)FORMATNUMBER(-23; 2; 2; TRUE; 1; TRUE)

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:

FORMATNUMBER(23, 2, 2, TRUE, 1, TRUE, "$")FORMATNUMBER(23; 2; 2; TRUE; 1; TRUE; "$")

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:

FORMATNUMBER(23, 2, 2, FALSE, 1, FALSE, "$")FORMATNUMBER(23; 2; 2; FALSE; 1; FALSE; "$")
FORMATNUMBER(Number: 23, MinimumNumberOfDecimalPlaces: 2, MaximumNumberOfDecimalPlaces: 2, OmitThousandsSeparators: FALSE, MinimumNumberOfIntegerDigits: 1, UseAccountingStyle: FALSE, LeadingUnit: "$")FORMATNUMBER(Number: 23; MinimumNumberOfDecimalPlaces: 2; MaximumNumberOfDecimalPlaces: 2; OmitThousandsSeparators: FALSE; MinimumNumberOfIntegerDigits: 1; UseAccountingStyle: FALSE; LeadingUnit: "$")

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:

FORMATNUMBER(23, LeadingUnit: "$")FORMATNUMBER(23; LeadingUnit: "$")

Use named parameters when they help make a formula easier to read.

Related functions

Examples

FORMATNUMBER(Field1)FORMATNUMBER(Field1)

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.

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({ 1003.75, 0.213 }, 2)FORMATNUMBER({ 1003,75; 0,213 }; 2)

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.

FORMATNUMBER(1003.75, 4)FORMATNUMBER(1003,75; 4)

Returns "1,003.7500" if the language of the app is set to US English, using exactly four decimal places.

FORMATNUMBER(1003, 2, 6)FORMATNUMBER(1003; 2; 6)

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.

FORMATNUMBER(1003.123456789, 2, 6)FORMATNUMBER(1003,123456789; 2; 6)

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.

FORMATNUMBER(1024.816, OmitThousandsSeparators: TRUE)FORMATNUMBER(1024,816; OmitThousandsSeparators: TRUE)

Returns "1024.82" (for an app set to US English), and not "1,024.82". Thousands separators are not used.

FORMATNUMBER(1003.75, OmitThousandsSeparators: TRUE, MinimumNumberOfIntegerDigits: 4)FORMATNUMBER(1003,75; OmitThousandsSeparators: TRUE; MinimumNumberOfIntegerDigits: 4)

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.

FORMATNUMBER(-23, UseAccountingStyle: TRUE)FORMATNUMBER(-23; UseAccountingStyle: TRUE)

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.

FORMATNUMBER(-23, UseAccountingStyle: TRUE, LeadingUnit: "$")FORMATNUMBER(-23; UseAccountingStyle: TRUE; LeadingUnit: "$")

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 "$".

FORMATNUMBER(23, 0, TrailingUnit: " lbs")FORMATNUMBER(23; 0; TrailingUnit: " lbs")

Returns "23 lbs". The trailing unit is set to " lbs".