Home

Awesome

Go Reference CI

numfmt

numfmt is a number formatting package for Go.

Features

Examples

Use directly from Go:

f := &numfmt.Formatter{
  NegativeTemplate: "(n)",
  MinDecimalPlaces: 2,
}
f.Format("-1234") // => "(1,234.00)"

Or in use in text/template:

{{numfmt "1234.5"}} => "1,234.5"
{{numfmt "GroupSeparator" " " "DecimalSeparator" "," "1234.5"}} => "1 234,5"

See the documentation for more examples.