frontend/templates: fix money rendering
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
fc272ffb7b
commit
75135e6c7f
4 changed files with 12 additions and 11 deletions
|
@ -17,7 +17,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
templates = template.Must(template.ParseGlob("templates/*.html"))
|
||||
templates = template.Must(template.New("").
|
||||
Funcs(template.FuncMap{
|
||||
"renderMoney": renderMoney,
|
||||
}).ParseGlob("templates/*.html"))
|
||||
)
|
||||
|
||||
func ensureSessionID(next http.HandlerFunc) http.HandlerFunc {
|
||||
|
@ -282,3 +285,7 @@ func cartIDs(c []*pb.CartItem) []string {
|
|||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func renderMoney(money pb.Money) string {
|
||||
return fmt.Sprintf("%s %d.%02d", money.GetCurrencyCode(), money.GetUnits(), money.GetNanos()/10000000)
|
||||
}
|
||||
|
|
|
@ -26,9 +26,7 @@
|
|||
<div class="col text-left">
|
||||
Qty: {{.Quantity}}<br/>
|
||||
<strong>
|
||||
{{.Price.CurrencyCode}}
|
||||
{{.Price.Amount.Decimal}}.
|
||||
{{- .Price.Amount.Fractional}}{{- if lt .Price.Amount.Fractional 10}}0{{end}}
|
||||
{{ renderMoney .Price}}
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -38,10 +38,8 @@
|
|||
</a>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
{{.Price.CurrencyCode}}
|
||||
<strong>{{.Price.Amount.Decimal}}.{{.Price.Amount.Fractional}}
|
||||
{{- if lt .Price.Amount.Fractional 10}}0{{end}}
|
||||
</strong>
|
||||
{{ renderMoney .Price }}
|
||||
</strong>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
<h2>{{$.product.Item.Name}}</h2>
|
||||
|
||||
<p class="text-muted">
|
||||
{{$.product.Price.CurrencyCode}}
|
||||
{{$.product.Price.Amount.Decimal}}.
|
||||
{{- $.product.Price.Amount.Fractional}}{{- if lt $.product.Price.Amount.Fractional 10}}0{{end}}
|
||||
{{ renderMoney $.product.Price}}
|
||||
</p>
|
||||
<hr/>
|
||||
<p>
|
||||
|
|
Loading…
Reference in a new issue