digits-2023-10-15/digits-work-sample-go.d/amount.go

19 lines
455 B
Go

package analyzer
import "math"
type Amount float64
// Rounded rounds a float to the number of places specified.
func (amount Amount) Rounded(places int) Amount {
p := math.Pow10(places)
return Amount(math.Round(float64(amount)*p) / p)
}
// 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 ""
}