diff --git a/services/templater.go b/services/templater.go index 0824297..a475f4e 100644 --- a/services/templater.go +++ b/services/templater.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "html/template" + "math" "strings" "go.uber.org/zap" @@ -91,7 +92,15 @@ func (t *DefaultTemplater) FormatUnit(unit string, locale string, amount int) (s var formatted string switch unit { case "kilometer": - formatted = fmt.Sprintf("%.3f", float64(amount)/1000) + if amount < 1000 { + formatted = fmt.Sprintf("%dm", amount) + } else if (amount % 1000) == 0 { + formatted = fmt.Sprintf("%dkm", amount/1000) + } else { + kilometers := math.Floor(float64(amount) / 1000) + meters := amount - int(kilometers)*1000 + formatted = fmt.Sprintf("%dkm %dm", int(kilometers), meters) + } case "euro": formatted = fmt.Sprintf("%.2f", float64(amount)/100) default: diff --git a/static/templates/certificate/de.html b/static/templates/certificate/de.html index 1596ef0..1b8da87 100644 --- a/static/templates/certificate/de.html +++ b/static/templates/certificate/de.html @@ -56,7 +56,7 @@ {{ .MiddleName }} {{ .LastName }}
hat beim {{ $.EventName }}
-{{formatUnit "kilometer" $.Locale .Distance}}km
+{{formatUnit "kilometer" $.Locale .Distance}}
für den guten Zweck zurückgelegt.