Documentation ¶
Index ¶
- Variables
- func MaxPrec(in []Decimal) int
- func ToElegantFloat64s(in []Decimal) []gnum.ElegantFloat
- func ToFloat64s(in []Decimal) []float64
- type Decimal
- func Max(first Decimal, args ...Decimal) Decimal
- func Min(first Decimal, args ...Decimal) Decimal
- func NewFromDecimal(d2 decimal.Decimal) Decimal
- func NewFromFloat64(val float64) Decimal
- func NewFromInt(val int) Decimal
- func NewFromInt64(val int64) Decimal
- func NewFromString(val string) (Decimal, error)
- func NewFromStringEx(val string, prec int) (Decimal, error)
- func NewFromUint(val uint) Decimal
- func NewFromUint64(val uint64) Decimal
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(d2 Decimal) Decimal
- func (d Decimal) AddFloat64(n float64) Decimal
- func (d Decimal) AddInt(n int) Decimal
- func (d Decimal) BitsAfterDecimalPoint() int
- func (d Decimal) Div(d2 Decimal) Decimal
- func (d Decimal) DivFloat64(n float64) Decimal
- func (d Decimal) DivInt(n int) Decimal
- func (d Decimal) DivRound(d2 Decimal, precision int) Decimal
- func (d Decimal) DivRoundDown(d2 Decimal, precision int) Decimal
- func (d Decimal) DivRoundFloat64(d2 float64, precision int) Decimal
- func (d Decimal) DivRoundInt(d2 int, precision int) Decimal
- func (d Decimal) Equal(cmp Decimal) bool
- func (d Decimal) EqualFloat64(cmp float64) bool
- func (d Decimal) EqualInt(cmp int) bool
- func (d Decimal) Float64() float64
- func (d Decimal) Float64Ex() (val float64, exact bool)
- func (d Decimal) GreaterThan(cmp Decimal) bool
- func (d Decimal) GreaterThanFloat64(cmp float64) bool
- func (d Decimal) GreaterThanInt(cmp int) bool
- func (d Decimal) GreaterThanOrEqual(cmp Decimal) bool
- func (d Decimal) GreaterThanOrEqualFloat64(cmp float64) bool
- func (d Decimal) GreaterThanOrEqualInt(cmp int) bool
- func (d Decimal) Int64Part() int64
- func (d Decimal) IntPart() int
- func (d Decimal) IsNegative() bool
- func (d Decimal) IsPositive() bool
- func (d Decimal) IsZero() bool
- func (d Decimal) LessThan(cmp Decimal) bool
- func (d Decimal) LessThanFloat64(cmp float64) bool
- func (d Decimal) LessThanInt(cmp int) bool
- func (d Decimal) LessThanOrEqual(cmp Decimal) bool
- func (d Decimal) LessThanOrEqualFloat64(cmp float64) bool
- func (d Decimal) LessThanOrEqualInt(cmp int) bool
- func (d Decimal) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (d Decimal) MarshalBinary() (data []byte, err error)
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) MarshalJSONWithoutQuotes() ([]byte, error)
- func (d Decimal) MarshalText() (text []byte, err error)
- func (d Decimal) Mul(d2 Decimal) Decimal
- func (d Decimal) MulFloat64(n float64) Decimal
- func (d Decimal) MulInt(n int) Decimal
- func (d *Decimal) SetFloat64(val float64)
- func (d *Decimal) SetInt(val int)
- func (d Decimal) String() string
- func (d Decimal) Sub(d2 Decimal) Decimal
- func (d Decimal) SubFloat64(n float64) Decimal
- func (d Decimal) SubInt(n int) Decimal
- func (d *Decimal) ToBSONDecimal128() (primitive.Decimal128, error)
- func (d *Decimal) ToElegantFloat() gnum.ElegantFloat
- func (d Decimal) Trunc(prec int, step float64) Decimal
- func (d Decimal) Trunc2(min Decimal, step float64) Decimal
- func (d Decimal) TurnPositiveNegative() Decimal
- func (d *Decimal) UnmarshalBSONValue(t bsontype.Type, data []byte) error
- func (d *Decimal) UnmarshalBinary(b []byte) error
- func (d *Decimal) UnmarshalJSON(b []byte) error
- func (d *Decimal) UnmarshalText(text []byte) error
- func (d Decimal) WithPrec(prec int) Decimal
Constants ¶
This section is empty.
Variables ¶
var ( Zero = Decimal(decimal.Zero) One = NewFromInt(1) N0 = Decimal(decimal.Zero) N1 = NewFromInt(1) )
Functions ¶
func ToElegantFloat64s ¶
func ToElegantFloat64s(in []Decimal) []gnum.ElegantFloat
func ToFloat64s ¶
Types ¶
type Decimal ¶
func NewFromDecimal ¶
func NewFromFloat64 ¶
func NewFromInt ¶
func NewFromInt64 ¶
func NewFromString ¶
func NewFromUint ¶
func NewFromUint64 ¶
func (Decimal) AddFloat64 ¶
func (Decimal) BitsAfterDecimalPoint ¶
func (Decimal) DivFloat64 ¶
func (Decimal) DivRoundFloat64 ¶
func (Decimal) EqualFloat64 ¶
func (Decimal) GreaterThan ¶
func (Decimal) GreaterThanFloat64 ¶
func (Decimal) GreaterThanInt ¶
func (Decimal) GreaterThanOrEqual ¶
func (Decimal) GreaterThanOrEqualFloat64 ¶
func (Decimal) GreaterThanOrEqualInt ¶
func (Decimal) IsNegative ¶
func (Decimal) IsPositive ¶
func (Decimal) LessThanFloat64 ¶
func (Decimal) LessThanInt ¶
func (Decimal) LessThanOrEqual ¶
func (Decimal) LessThanOrEqualFloat64 ¶
func (Decimal) LessThanOrEqualInt ¶
func (Decimal) MarshalBSONValue ¶
in BSON, Decimal128 could has 34 numbers after decimal point, it will loss precision if more than 34 numbers after decimal point so we serialize Decimal into string, just like in JSON. in BSON, omitempty of Decimal works reference: https://github.com/hackeryard/configcenter/blob/a9638f554b4cf47fb13c37c5c3611e1e0696fd25/src/common/metadata/time.go#L94
func (Decimal) MarshalBinary ¶
func (Decimal) MarshalJSON ¶
NOTE: if omitempty required in JSON, use *Decimal in your structure, no other way to implement this even you change source code MarshalJSON function in shopsprint/decimal
func (Decimal) MarshalJSONWithoutQuotes ¶
WARNING: this is dangerous for decimals with many digits, since many JSON unmarshallers (ex: Javascript's) will unmarshal JSON numbers to IEEE 754 double-precision floating point numbers, which means you can potentially silently lose precision.
func (Decimal) MarshalText ¶
func (Decimal) MulFloat64 ¶
func (*Decimal) SetFloat64 ¶
func (Decimal) SubFloat64 ¶
func (*Decimal) ToBSONDecimal128 ¶
func (d *Decimal) ToBSONDecimal128() (primitive.Decimal128, error)
WARN: BSON Decimal128 has max 34 number after "." but Decimal doesn't have this limit (limited by your memory)
func (*Decimal) ToElegantFloat ¶
func (d *Decimal) ToElegantFloat() gnum.ElegantFloat