转到模板:货币管道格式?

I'm trying to represent money in a go template. {{.cash}}

But right now, cash comes as 1000000

Would it be possible to make it output 1,000,000 ?

Is there some sort of {{.cash | Currency}} formatter? If not, how do I go about getting the desired output?

Thanks.

You can leverage github.com/dustin/go-humanize to do this.

funcMap := template.FuncMap{
    "comma": humanize.Comma,
}
t := template.New("").Funcs(templateFuncs).Parse(`A million: {{comma .}}`)
err := tmpl.Execute(os.Stdout, 1000000)
if err != nil {
  log.Fatalf("execution: %s", err)
}
// A million: 1,000,000