Clarify "precision" in currency format functions
authorPaul Gottschling <paul.gottschling@gmail.com>
Thu, 2 Sep 2021 00:26:42 +0000 (20:26 -0400)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 22 Sep 2021 18:00:30 +0000 (20:00 +0200)
The documentation of the FormatAccounting and FormatCurrency
functions could be clearer in terms of how the precision param
works. This commit makes it more explicit that adding a precision
of < 2 will not format the return values to include fewer decimals.

Resolves #8858

tpl/lang/lang.go

index 0e170e041c270aa99499d410d5e668f1099797de..3fb321e1abb6c30b27a99b817e51c01d0ff1ead7 100644 (file)
@@ -80,8 +80,10 @@ func (ns *Namespace) FormatPercent(precision, number interface{}) (string, error
        return ns.translator.FmtPercent(n, p), nil
 }
 
-// FormatCurrency returns the currency reprecentation of number for the given currency and precision
+// FormatCurrency returns the currency representation of number for the given currency and precision
 // for the current language.
+//
+// The return value is formatted with at least two decimal places.
 func (ns *Namespace) FormatCurrency(precision, currency, number interface{}) (string, error) {
        p, n, err := ns.castPrecisionNumber(precision, number)
        if err != nil {
@@ -94,8 +96,10 @@ func (ns *Namespace) FormatCurrency(precision, currency, number interface{}) (st
        return ns.translator.FmtCurrency(n, p, c), nil
 }
 
-// FormatAccounting returns the currency reprecentation of number for the given currency and precision
+// FormatAccounting returns the currency representation of number for the given currency and precision
 // for the current language in accounting notation.
+//
+// The return value is formatted with at least two decimal places.
 func (ns *Namespace) FormatAccounting(precision, currency, number interface{}) (string, error) {
        p, n, err := ns.castPrecisionNumber(precision, number)
        if err != nil {