implement amount.go:Amount:FormatUSD with localizedLanguagePrinter
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user