HUGO
Menu
GitHub 87548 stars Mastodon

lang.FormatNumberCustom

Returns a numeric representation of a number with the given precision using negative, decimal, and grouping options.

Syntax

lang.FormatNumberCustom PRECISION NUMBER [OPTIONS...]

Returns

string

This function formats a number with the given precision. The first options parameter is a space-delimited string of characters to represent negativity, the decimal point, and grouping. The default value is - . ,. The second options parameter defines an alternative delimiting character.

Note that numbers are rounded up at 5 or greater. So, with precision set to 0, 1.5 becomes 2, and 1.4 becomes 1.

For a simpler function that adapts to the current language, see lang.FormatNumber.

{{ lang.FormatNumberCustom 2 12345.6789 }} → 12,345.68
{{ lang.FormatNumberCustom 2 12345.6789 "- , ." }} → 12.345,68
{{ lang.FormatNumberCustom 6 -12345.6789 "- ." }} → -12345.678900
{{ lang.FormatNumberCustom 0 -12345.6789 "- . ," }} → -12,346
{{ lang.FormatNumberCustom 0 -12345.6789 "-|.| " "|" }} → -12 346

日期、货币、数字和百分比的本地化由 gohugoio/locales 包执行。当前站点的语言标签必须与列出的语言区域之一匹配。


Last updated: January 1, 0001
Improve this page