Documentation ¶
Index ¶
- Variables
- type Decimal
- func (d Decimal) Add(y Decimal) Decimal
- func (d Decimal) Cmp(y Decimal) int
- func (d Decimal) Div(y Decimal, scale int) Decimal
- func (d Decimal) DivInt64(y int64) Decimal
- func (d Decimal) Float64() float64
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) Mul(y Decimal) Decimal
- func (d Decimal) MulInt64(y int64) Decimal
- func (d Decimal) Neg() Decimal
- func (d Decimal) Sign() int
- func (d Decimal) String() string
- func (d Decimal) Sub(y Decimal) Decimal
- func (d Decimal) ToScale(scale int) Decimal
- func (d *Decimal) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedDecimalNotation = errors.New("luno: unsupported decimal notation")
Functions ¶
This section is empty.
Types ¶
type Decimal ¶
type Decimal struct {
// contains filtered or unexported fields
}
Decimal represents a decimal amount, internally stored as a big.Int.
func New ¶
New returns a new Decimal. scale specifies the units of i as an inverse power of 10. For example, a scale of 2 indicates that i is in units of 10^-2, and a value of i=25 would represent 25*10^-2=0.25. If scale=0, then the decimal is an integer.
func NewFromFloat64 ¶
NewFromFloat64 returns a new Decimal with the given scale. The value is truncated towards 0.
func NewFromInt64 ¶
func NewFromString ¶
func (Decimal) Div ¶
Div divides d by y and returns the result in the provided scale. If the provided scale is too small for the result of d/y, the result is truncated towards 0. d is left unchanged.
func (Decimal) MarshalJSON ¶
MarshalJSON converts the Decimal to JSON bytes.
func (Decimal) Mul ¶
Mul multiplies d by y and returns the result. The result has a scale equal to the sum of d's and y's scales. d is left unchanged.
func (Decimal) ToScale ¶
ToScale returns a Decimal representing the same value as d, but with the given scale. If scale is less than the Decimal's current scale, i.e. the new Decimal has fewer decimal points, the decimal is truncated (rounded towards 0). d is left unchanged.
func (*Decimal) UnmarshalJSON ¶
UnmarshalJSON reads JSON bytes into a Decimal.