diff --git a/cmd/web/render.go b/cmd/web/render.go index 5316472..1c73cb6 100644 --- a/cmd/web/render.go +++ b/cmd/web/render.go @@ -22,7 +22,14 @@ type templateData struct { IsAuthenticated int } -var functions = template.FuncMap{} +var functions = template.FuncMap{ + "formatCurrency": formatCurrency, +} + +func formatCurrency(n int) string { + f := float32(n / 100) + return fmt.Sprintf("€%.2f", f) +} //go:embed templates var templateFS embed.FS diff --git a/cmd/web/templates/buy-once.page.gohtml b/cmd/web/templates/buy-once.page.gohtml index 4b18ff4..21785d1 100644 --- a/cmd/web/templates/buy-once.page.gohtml +++ b/cmd/web/templates/buy-once.page.gohtml @@ -19,8 +19,8 @@ Buy one widget autocomplete="off" novalidate=""> - -

{{$widget.Name}}: {{$widget.Price}}

+ +

{{$widget.Name}}: {{formatCurrency $widget.Price}}

{{$widget.Description}}