Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidValue = errors.New("one of the specified money values is invalid") ErrMismatchingCurrency = errors.New("mismatching currency codes") )
Functions ¶
func AreEquals ¶
AreEquals returns true if values l and r are the equal, including the currency. This does not check validity of the provided values.
func AreSameCurrency ¶
AreSameCurrency returns true if values l and r have a currency code and they are the same values.
func IsNegative ¶
IsNegative returns true if the specified money value is valid and is negative.
func IsPositive ¶
IsPositive returns true if the specified money value is valid and is positive.
Types ¶
type T ¶
type T struct { weaver.AutoMarshal // The 3-letter currency code defined in ISO 4217. CurrencyCode string `json:"currencyCode"` // The whole units of the amount. // For example if `currencyCode` is `"USD"`, then 1 unit is one US dollar. Units int64 `json:"units"` // Number of nano (10^-9) units of the amount. // The value must be between -999,999,999 and +999,999,999 inclusive. // If `units` is positive, `nanos` must be positive or zero. // If `units` is zero, `nanos` can be positive, zero, or negative. // If `units` is negative, `nanos` must be negative or zero. // For example $-1.75 is represented as `units`=-1 and `nanos`=-750,000,000. Nanos int32 `json:"nanos"` }
T represents an amount of money along with the currency type.
func MultiplySlow ¶
MultiplySlow is a slow multiplication operation done through adding the value to itself n-1 times.
func Must ¶
Must panics if the given error is not nil. This can be used with other functions like: "m := Must(Sum(a,b))".
func Sum ¶
Sum adds two values. Returns an error if one of the values are invalid or currency codes are not matching (unless currency code is unspecified for both).