diff --git a/digits-work-sample-go.d/amount.go b/digits-work-sample-go.d/amount.go index 52fd4b4..31322fc 100644 --- a/digits-work-sample-go.d/amount.go +++ b/digits-work-sample-go.d/amount.go @@ -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) }