Documentation
¶
Index ¶
- Variables
- type Amount
- func (a Amount) Equal(other Amount) bool
- func (a *Amount) FromString(str string) error
- func (a *Amount) Int() int
- func (a Amount) MarshalJSON() ([]byte, error)
- func (a Amount) Plus(other Amount) (Amount, error)
- func (a *Amount) String() string
- func (a *Amount) UnmarshalJSON(b []byte) error
- func (a *Amount) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDifferentCurrencies is returned when an operation on an Amount instance is attempted with another Amount of a different currency (symbol). ErrDifferentCurrencies = errors.New("different currencies") )
Functions ¶
This section is empty.
Types ¶
type Amount ¶
type Amount struct {
// contains filtered or unexported fields
}
Amount represents units of a particular currency.
func NewAmountFromInt ¶
NewAmountFromInt returns an Amount object after converting an integer amount (in cents) and validating the ISO 4217 currency symbol.
func ParseAmount ¶
ParseAmount attempts to read a string as a valid currency symbol and number. Examples:
USD 12.53
func SumAmounts ¶
func (*Amount) FromString ¶
FromString attempts to parse str as a valid currency symbol and the quantity. Examples:
USD 12.53 GBP 4.02
func (Amount) MarshalJSON ¶
func (Amount) Plus ¶
Plus returns an Amount of adding both Amount instances together. Currency symbols must match for Plus to return without errors.
func (*Amount) String ¶
String returns an amount formatted with the currency. Examples:
USD 12.53 GBP 4.02
The symbol returned corresponds to the ISO 4217 standard. Only one period used to signify decimal value will be included.