Documentation ¶
Index ¶
- func RoundDown(f float64) int64
- func RoundHalfDown(f float64) int64
- func RoundHalfToEven(f float64) int64
- func RoundHalfUp(f float64) int64
- func RoundUp(f float64) int64
- type Money
- func (m Money) Abs() Money
- func (m Money) Add(v Money) Money
- func (m Money) Allocate(ratios ...int64) []Money
- func (m Money) Clone(value int64) Money
- func (m Money) Div(f float64) Money
- func (m Money) Eq(v Money) bool
- func (m Money) FlipSign() Money
- func (m Money) Gt(v Money) bool
- func (m Money) Gte(v Money) bool
- func (m Money) IsNeg() bool
- func (m Money) IsPos() bool
- func (m Money) IsZero() bool
- func (m Money) IsoCode() string
- func (m Money) Lt(v Money) bool
- func (m Money) Lte(v Money) bool
- func (m Money) MarshalJSON() ([]byte, error)
- func (m Money) Mul(n int64) Money
- func (m Money) Neq(v Money) bool
- func (m Money) Split(n int64) []Money
- func (m Money) String() string
- func (m Money) StringNoSymbol() string
- func (m Money) Sub(v Money) Money
- func (m Money) Subunits() int64
- func (m Money) Units() int64
- func (m Money) Value() int64
- type Price
- func (p *Price) AddTaxPercent(percent float64, desc string)
- func (p *Price) AddTaxSubunits(value int64, desc string)
- func (p Price) Gross() Money
- func (p *Price) IncludeTaxPercent(percent float64, desc string)
- func (p *Price) IncludeTaxSubunits(value int64, desc string)
- func (p Price) IsoCode() string
- func (p Price) MarshalJSON() ([]byte, error)
- func (p Price) Net() Money
- func (p Price) String() string
- func (p Price) StringNoSymbol() string
- func (p Price) Tax() Money
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RoundHalfDown ¶
RoundHalfDown is a standard rounding function that rounds 0.5 and below down.
func RoundHalfToEven ¶
RoundHalfToEven is a standard rounding function that rounds 0.5 to the nearest even number. This is sometimes called bankers rounding.
func RoundHalfUp ¶
RoundHalfUp is a standard rounding function that rounds 0.5 and above up.
Types ¶
type Money ¶
type Money struct {
// contains filtered or unexported fields
}
Money is the main structure that holds a monetary value and how to format it as a string.
func MoneyFromString ¶
MoneyFromString constructs a new money object from a string. Everything not contained within a number is stripped out before parsing. currIsoCode is an ISO 4217 currency code. value is monetary value in subunits. roundFunc is a function to be used for division operations.
func MoneyFromSubunits ¶
MoneyFromSubunits constructs a new money object from an integer. The integer used should represent the subunits of the currency. currIsoCode is an ISO 4217 currency code. value is monetary value in subunits. roundFunc is a function to be used for division operations.
func (Money) Allocate ¶
Allocate returns a slice containing money objects split according to the passed ratios. The ratios are completely arbitrary and are calculated as percentages of the overall sum. This operation is lossless and will account for all remainders.
func (Money) Div ¶
Div is an arithmetic operator. This operation will perform rounding of the resulting value using the assigned rounding function. If you need to accurately divide a money object with lossless precision, use the Split or Allocate functions instead.
func (Money) FlipSign ¶
FlipSign flips the sign of the money object's value. Switching positive to negative and vice versa.
func (Money) MarshalJSON ¶
MarshalJSON is an implementation of json.Marshaller.
func (Money) Split ¶
Split returns a slice containing money objects split as evenly as possible by 'n' times. This operation is lossless and will account for all remainders.
func (Money) String ¶
String is an implementation of fmt.Stringer and returns the string formatted representation of the monetary value.
func (Money) StringNoSymbol ¶
StringNoSymbol returns the string formatted representation of the monetary value without a currency symbol.
type Price ¶
type Price struct {
// contains filtered or unexported fields
}
Price is a structure that holds a price and gives information about the amount of tax applied to that price.
func PriceFromString ¶
MoneyFromString constructs a new price object from a string and tax percentage. Everything not contained within a number is stripped out before parsing. currIsoCode is an ISO 4217 currency code. value is monetary value in subunits. roundFunc is a function to be used for division operations.
func PriceFromSubunits ¶
PriceFromSubunits constructs a new price object from an integer and tax percentage. The value integer used should represent the subunits of the currency. currIsoCode is an ISO 4217 currency code. value is monetary value in subunits. roundFunc is a function to be used for division operations.
func (*Price) AddTaxPercent ¶ added in v1.1.0
AddTaxPercentage adds a tax to the price using a percentage. This will literally add a percentage to the gross price.
func (*Price) AddTaxSubunits ¶ added in v1.1.0
AddTaxSubunits adds a tax to the price using subunits. This will literally add a subunit amount to the gross price.
func (*Price) IncludeTaxPercent ¶ added in v1.1.0
AddTaxPercentage adds a tax to the price using a percentage. This implies this tax is already included in the gross price.
func (*Price) IncludeTaxSubunits ¶ added in v1.1.0
IncludeTaxSubunits adds a tax to the price using subunits. This implies this tax is already included in the gross price.
func (Price) MarshalJSON ¶
MarshalJSON is an implementation of json.Marshaller.
func (Price) Net ¶
Net returns the net monetary value of the price which is equal to the gross minus tax.
func (Price) String ¶
String is an implementation of fmt.Stringer and returns the string formatted representation of the price value.
func (Price) StringNoSymbol ¶
StringNoSymbol returns the string formatted representation of the price value without a currency symbol.