Creating a formatCurrency function

This commit is contained in:
vinchent 2024-08-06 20:52:46 +02:00
parent 20f7bd529f
commit f952caf3f6
2 changed files with 10 additions and 3 deletions

View File

@ -22,7 +22,14 @@ type templateData struct {
IsAuthenticated int 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 //go:embed templates
var templateFS embed.FS var templateFS embed.FS

View File

@ -19,8 +19,8 @@ Buy one widget
autocomplete="off" autocomplete="off"
novalidate=""> novalidate="">
<input type="hidden" name="product_id" value="{{$widget.ID}}"> <input type="hidden" name="product_id" value="{{$widget.ID}}">
<input type="hidden" name="amount" value="{{$widget.Price}}"> <input type="hidden" id="amount" name="amount" value="{{$widget.Price}}">
<h3 class="mt-2 mb-3 text-center">{{$widget.Name}}: {{$widget.Price}}</h3> <h3 class="mt-2 mb-3 text-center">{{$widget.Name}}: {{formatCurrency $widget.Price}}</h3>
<p class="mt-2 mb-3 text-center">{{$widget.Description}}</p> <p class="mt-2 mb-3 text-center">{{$widget.Description}}</p>
<hr> <hr>