lang.FormatNumberCustom
Returns a numeric representation of a number with the given precision using negative, decimal, and grouping options.
- Syntax
- lang.FormatNumberCustom PRECISION NUMBER [FORMAT] [DELIMITER]
- Returns
- string
Usage
The lang.FormatNumberCustom function returns a numeric representation of NUMBER, rounded to PRECISION decimal places, using the minus sign, decimal separator, and grouping separator defined in FORMAT. The function rounds halfway values away from zero, so with PRECISION set to 0, 1.5 becomes 2 and -1.5 becomes -2.
The result does not depend on the current language and region. To format a number for the current language and region, use the lang.FormatNumber function instead.
Arguments
PRECISION- (
int) The number of decimal places. NUMBER- (
intorfloat) The number to format. FORMAT- (
string) The minus sign, decimal separator, and grouping separator, in that order, separated byDELIMITER. If you specify fewer than three fields, the function omits the characters for the missing fields. Default is- . ,. DELIMITER- (
string) The delimiter between the fields inFORMAT. Use a different delimiter when one of the fields is a space. Default is a space.
Examples
{{ lang.FormatNumberCustom 2 12345.6789 }} → 12,345.68
{{ lang.FormatNumberCustom 0 -12345.6789 "- . ," }} → -12,346Swapping the decimal and grouping separators:
{{ lang.FormatNumberCustom 2 12345.6789 "- , ." }} → 12.345,68Omitting the grouping separator:
{{ lang.FormatNumberCustom 6 -12345.6789 "- ." }} → -12345.678900Using a space as the grouping separator, with a custom delimiter:
{{ lang.FormatNumberCustom 0 -12345.6789 "-|.| " "|" }} → -12 346Last updated:
November 21, 2026
:
content: Apply style guide to lang functions (ff0d3f8c7)
Improve this page