implement amount.go:Amount:FormatUSD with localizedLanguagePrinter
parent
ea64f6ea98
commit
33c8b9be0b
|
|
@ -52,7 +52,14 @@ func (amount Amount) Rounded(places int) Amount {
|
|||
|
||||
// FormatUSD formats Amount as a string in US dollars.
|
||||
func (amount Amount) FormatUSD() string {
|
||||
// TODO: Not implemented.
|
||||
// Hint: Number localization gets tricky. Can you find a library to help?
|
||||
return ""
|
||||
rounded := amount.Rounded(2)
|
||||
prefix := ""
|
||||
if rounded < 0 {
|
||||
prefix = "-"
|
||||
rounded *= -1.0
|
||||
}
|
||||
|
||||
roundedAsCurrency := currency.NarrowSymbol(currency.USD.Amount(float32(rounded)))
|
||||
resultWithSpaceAfterDollarSign := localizedLanguagePrinter.Sprintf("%s%.2f", prefix, roundedAsCurrency)
|
||||
return strings.Replace(resultWithSpaceAfterDollarSign, "$ ", "$", 1)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue