From 39a97be752991c428ae94e0049830a154257f2b0 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Wed, 28 Dec 2016 22:09:31 -0600 Subject: [PATCH] tpl/lang: Add NumFmt function NumFmt formats a number with a given precision using the requested decimal, grouping, and negative characters. Fixes #1444 --- content/templates/functions.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/content/templates/functions.md b/content/templates/functions.md index c1fd8ebad..c514a4ec8 100644 --- a/content/templates/functions.md +++ b/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 ` `. 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