model

package
v0.8.0-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 NewAmount

func NewAmount(symbol string, number string) (*Amount, error)

NewAmount returns an Amount object after validating the ISO 4217 currency symbol.

func NewAmountFromInt

func NewAmountFromInt(symbol string, number int) (*Amount, error)

NewAmountFromInt returns an Amount object after converting an integer amount (in cents) and validating the ISO 4217 currency symbol.

func ParseAmount

func ParseAmount(in string) (*Amount, error)

ParseAmount attempts to read a string as a valid currency symbol and number. Examples:

USD 12.53

func SumAmounts

func SumAmounts(amounts ...string) (*Amount, error)

func (Amount) Equal

func (a Amount) Equal(other Amount) bool

func (*Amount) FromString

func (a *Amount) FromString(str string) error

FromString attempts to parse str as a valid currency symbol and the quantity. Examples:

USD 12.53
GBP 4.02

func (*Amount) Int

func (a *Amount) Int() int

Int returns the currency amount as an integer. Example: "USD 1.11" returns 111

func (Amount) MarshalJSON

func (a Amount) MarshalJSON() ([]byte, error)

func (Amount) Plus

func (a Amount) Plus(other Amount) (Amount, error)

Plus returns an Amount of adding both Amount instances together. Currency symbols must match for Plus to return without errors.

func (*Amount) String

func (a *Amount) String() 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.

func (*Amount) UnmarshalJSON

func (a *Amount) UnmarshalJSON(b []byte) error

func (*Amount) Validate

func (a *Amount) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL