Documentation ¶
Overview ¶
Package money implements utility routines for manipulating monetary values.
This package is a basic implementation of Google's micros https://developers.google.com/standard-payments/reference/glossary#micros Storing monetary values as integer by multiplying / dividing it by 1,000,000. For example £1.23 is stored as 1230000.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Money ¶
type Money int64
Store monetary values as integer.
func New ¶
New initializes and return a Money. It accepts integer and float types. For float types, he input will be rounded to the nearest integer using math.RoundToEven().
func NewFromString ¶
NewForString initializes and return a Money. It accepts an arbitrary string containing a number. The number is converted to float64 then rounded to the nearest integer using math.RoundToEven(). If the conversion fails, an error is returned.
func (Money) DisplayCurrency ¶
DisplayCurrency returns a rounded Money as a string with comma thousands separators.
func (Money) Div ¶
Div returns a Money divided by a provided float64. If the divisor is 0, the Money will be returned as-is.
func (Money) Format ¶
Format returns a Money as a string with the specified digits. For example 66498000 with digits = 2 is returned as 66.50.