dollarize the money
This commit is contained in:
+10
-1
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
@@ -9,13 +10,21 @@ import (
|
||||
var cachedTemplates = map[string]*template.Template{}
|
||||
var cachedMutex sync.Mutex
|
||||
|
||||
func dollarize(value int) string {
|
||||
return fmt.Sprintf("$%0.2f", float32(value)/100.0)
|
||||
}
|
||||
|
||||
var funcs = template.FuncMap{
|
||||
"dollarize": dollarize,
|
||||
}
|
||||
|
||||
func T(name string) *template.Template {
|
||||
cachedMutex.Lock()
|
||||
defer cachedMutex.Unlock()
|
||||
if t, ok := cachedTemplates[name]; ok {
|
||||
return t
|
||||
}
|
||||
t := template.New("_base.html")
|
||||
t := template.New("_base.html").Funcs(funcs)
|
||||
t = template.Must(t.ParseFiles(
|
||||
"templates/_base.html",
|
||||
filepath.Join(*template_dir, name),
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
{{ .Name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ .Money }}
|
||||
{{ dollarize .Money }}
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
|
||||
Reference in New Issue
Block a user