| 1 |
--- |
| 2 |
title: lang.FormatNumberCustom |
| 3 |
description: Returns a numeric representation of a number with the given precision using negative, decimal, and grouping options. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: string |
| 10 |
signatures: ['lang.FormatNumberCustom PRECISION NUMBER [OPTIONS...]'] |
| 11 |
aliases: ['/functions/numfmt/'] |
| 12 |
--- |
| 13 |
|
| 14 |
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. |
| 15 |
|
| 16 |
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. |
| 17 |
|
| 18 |
For a simpler function that adapts to the current language, see [`lang.FormatNumber`][]. |
| 19 |
|
| 20 |
```go-html-template |
| 21 |
{{ lang.FormatNumberCustom 2 12345.6789 }} → 12,345.68 |
| 22 |
{{ lang.FormatNumberCustom 2 12345.6789 "- , ." }} → 12.345,68 |
| 23 |
{{ lang.FormatNumberCustom 6 -12345.6789 "- ." }} → -12345.678900 |
| 24 |
{{ lang.FormatNumberCustom 0 -12345.6789 "- . ," }} → -12,346 |
| 25 |
{{ lang.FormatNumberCustom 0 -12345.6789 "-|.| " "|" }} → -12 346 |
| 26 |
``` |
| 27 |
|
| 28 |
{{% include "/_common/functions/locales.md" %}} |
| 29 |
|
| 30 |
[`lang.FormatNumber`]: /functions/lang/formatnumber/ |