summaryrefslogtreecommitdiffhomepage
path: root/docs/content/templates/functions.md
diff options
context:
space:
mode:
authorCameron Moore <[email protected]>2016-12-28 22:09:31 -0600
committerBjørn Erik Pedersen <[email protected]>2017-05-18 09:49:20 +0300
commit93b3b1386714999d716e03b131f77234248f1724 (patch)
tree999a80a37b2ed0564ed72bbae89f4c240e6f39ce /docs/content/templates/functions.md
parente92ce83d5e8837190511f5a73323e49eeb8466cd (diff)
downloadhugo-93b3b1386714999d716e03b131f77234248f1724.tar.gz
hugo-93b3b1386714999d716e03b131f77234248f1724.zip
tpl/lang: Add NumFmt function
NumFmt formats a number with a given precision using the requested decimal, grouping, and negative characters. Fixes #1444
Diffstat (limited to 'docs/content/templates/functions.md')
-rw-r--r--docs/content/templates/functions.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/content/templates/functions.md b/docs/content/templates/functions.md
index c1fd8ebad..c514a4ec8 100644
--- a/docs/content/templates/functions.md
+++ b/docs/content/templates/functions.md
@@ -460,6 +460,24 @@ e.g.
* `{{ int "123" }}` → 123
+### lang.NumFmt
+
+`NumFmt` formats a number with the given precision using the *decimal*,
+*grouping*, and *negative* options. The `options` parameter is a
+string consisting of `<negative> <decimal> <grouping>`. The default
+`options` value is `- . ,`.
+
+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`.
+
+```
+{{ lang.NumFmt 2 12345.6789 }} → 12,345.68
+{{ lang.NumFmt 2 12345.6789 "- , ." }} → 12.345,68
+{{ lang.NumFmt 0 -12345.6789 "- . ," }} → -12,346
+{{ lang.NumFmt 6 -12345.6789 "- ." }} → -12345.678900
+{{ -98765.4321 | lang.NumFmt 2 }} → -98,765.43
+```
+
## Strings
### printf