Better format money
This commit is contained in:
+12
-2
@@ -72,8 +72,18 @@ func TimeToValue(time time.Time) string {
|
|||||||
func MoneyCentsToString(money int, currency string, lang Language) string {
|
func MoneyCentsToString(money int, currency string, lang Language) string {
|
||||||
beforeDecimals := money / 100
|
beforeDecimals := money / 100
|
||||||
afterDecimals := money % 100
|
afterDecimals := money % 100
|
||||||
|
|
||||||
|
if afterDecimals == 0 {
|
||||||
|
// Only show whole numbers when cents are 0
|
||||||
if lang == De {
|
if lang == De {
|
||||||
return fmt.Sprintf("%d,%d %s", beforeDecimals, afterDecimals, currency)
|
return fmt.Sprintf("%d %s", beforeDecimals, currency)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s%d.%d", currency, beforeDecimals, afterDecimals)
|
return fmt.Sprintf("%s%d", currency, beforeDecimals)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show cents with leading zero when < 10 (always two digits)
|
||||||
|
if lang == De {
|
||||||
|
return fmt.Sprintf("%d,%02d %s", beforeDecimals, afterDecimals, currency)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%d.%02d", currency, beforeDecimals, afterDecimals)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user