mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
tpl/lang: Add NumFmt function
NumFmt formats a number with a given precision using the requested decimal, grouping, and negative characters. Fixes #1444
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
e92ce83d5e
commit
93b3b13867
@@ -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
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user