Documentation ¶
Index ¶
- Variables
- type Decimal
- func (d Decimal) Add(d2 Decimal) Decimal
- func (d Decimal) Cmp(d2 Decimal) int
- func (d Decimal) DigitsAfterPeriod() int
- func (d Decimal) Div(d2 Decimal) Decimal
- func (d Decimal) DivPrecision(d2 Decimal, precision uint32) Decimal
- func (d Decimal) Equal(d2 Decimal) bool
- func (d Decimal) Float64() (float64, error)
- func (d Decimal) Greater(d2 Decimal) bool
- func (d Decimal) GreaterOrEqual(d2 Decimal) bool
- func (d Decimal) InRange(min, max Decimal) bool
- func (d Decimal) InRangeInt(min, max int64) bool
- func (d *Decimal) IsNegative() bool
- func (d Decimal) IsZero() bool
- func (d Decimal) Less(d2 Decimal) bool
- func (d Decimal) LessOrEqual(d2 Decimal) bool
- func (d Decimal) MarshalText() (text []byte, err error)
- func (d Decimal) Mul(d2 Decimal) Decimal
- func (d Decimal) MulInt(i int64) Decimal
- func (d Decimal) MustFloat64() float64
- func (d Decimal) Reduce() Decimal
- func (d Decimal) Round(n uint16) Decimal
- func (d *Decimal) RoundOrNil(n uint16) *Decimal
- func (d *Decimal) Scan(src interface{}) error
- func (d Decimal) String() string
- func (d Decimal) Sub(d2 Decimal) Decimal
- func (d *Decimal) UnmarshalJSON(b []byte) error
- func (d *Decimal) UnmarshalText(text []byte) error
- func (d Decimal) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var DivisionPrecision uint32 = 32
DivisionPrecision is the default precision for division used for all the `Decimal.Div` operations. It can be changed by setting `decimal.DivisionPrecision` to a different value.
Functions ¶
This section is empty.
Types ¶
type Decimal ¶
type Decimal struct {
// contains filtered or unexported fields
}
Decimal is an arbitrary-precision decimal.
func FromFloat64 ¶
FromFloat64 creates a new Decimal from a float64.
func MustFromStr ¶
MustFromStr creates a new Decimal from a string. It panics if the string is not a valid decimal.
func (Decimal) DigitsAfterPeriod ¶ added in v0.0.3
DigitsAfterPeriod returns number of digits after the period.
func (Decimal) DivPrecision ¶
DivPrecision divides the current decimal by a given one and returns the result with a given precision.
func (Decimal) GreaterOrEqual ¶
GreaterOrEqual returns true if d >= d2.
func (Decimal) InRangeInt ¶
InRangeInt returns true if d is in the range of [min, max] integers.
func (Decimal) LessOrEqual ¶
LessOrEqual returns true if d <= d2.
func (Decimal) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Decimal) MustFloat64 ¶
MustFloat64 returns the float64 representation of the decimal. It panics if the decimal can't be converted to float64.
func (*Decimal) RoundOrNil ¶
RoundOrNil returns nil if the Decimal is nil or rounds it to n digits after 0.
func (*Decimal) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Decimal) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.