diff options
author | Cameron Moore <[email protected]> | 2016-12-28 22:09:31 -0600 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-05-18 09:49:20 +0300 |
commit | 93b3b1386714999d716e03b131f77234248f1724 (patch) | |
tree | 999a80a37b2ed0564ed72bbae89f4c240e6f39ce /tpl/lang/init.go | |
parent | e92ce83d5e8837190511f5a73323e49eeb8466cd (diff) | |
download | hugo-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 'tpl/lang/init.go')
-rw-r--r-- | tpl/lang/init.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tpl/lang/init.go b/tpl/lang/init.go index 6cf8e790d..ea67afab0 100644 --- a/tpl/lang/init.go +++ b/tpl/lang/init.go @@ -34,6 +34,16 @@ func init() { [][2]string{}, ) + ns.AddMethodMapping(ctx.NumFmt, + nil, + [][2]string{ + {`{{ lang.NumFmt 2 12345.6789 }}`, `12,345.68`}, + {`{{ lang.NumFmt 2 12345.6789 "- , ." }}`, `12.345,68`}, + {`{{ lang.NumFmt 6 -12345.6789 "- ." }}`, `-12345.678900`}, + {`{{ lang.NumFmt 0 -12345.6789 "- . ," }}`, `-12,346`}, + {`{{ -98765.4321 | lang.NumFmt 2 }}`, `-98,765.43`}, + }, + ) return ns } |