8000 GitHub - jackc/numfmt: Number formatting in Go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jackc/numfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference CI

numfmt

numfmt is a number formatting package for Go.

Features

  • Rounding to N decimal places
  • Always display minimum of N decimal places
  • Configurable thousands separators
  • Scaling for percentage formatting
  • Format negative values differently for correct currency output like -$12.34 or (12.34)
  • Easy to use with text/template and html/template

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.

About

Number formatting in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0