gdecimal

package
v0.0.0-...-f3abbe6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Zero = Decimal(decimal.Zero)
	One  = NewFromInt(1)
	N0   = Decimal(decimal.Zero)
	N1   = NewFromInt(1)
)

Functions

func MaxPrec

func MaxPrec(in []Decimal) int

func ToElegantFloat64s

func ToElegantFloat64s(in []Decimal) []gnum.ElegantFloat

func ToFloat64s

func ToFloat64s(in []Decimal) []float64

Types

type Decimal

type Decimal decimal.Decimal

func Max

func Max(first Decimal, args ...Decimal) Decimal

func Min

func Min(first Decimal, args ...Decimal) Decimal

func NewFromDecimal

func NewFromDecimal(d2 decimal.Decimal) Decimal

func NewFromFloat64

func NewFromFloat64(val float64) Decimal

func NewFromInt

func NewFromInt(val int) Decimal

func NewFromInt64

func NewFromInt64(val int64) Decimal

func NewFromString

func NewFromString(val string) (Decimal, error)

func NewFromStringEx

func NewFromStringEx(val string, prec int) (Decimal, error)

func NewFromUint

func NewFromUint(val uint) Decimal

func NewFromUint64

func NewFromUint64(val uint64) Decimal

func (Decimal) Abs

func (d Decimal) Abs() Decimal

func (Decimal) Add

func (d Decimal) Add(d2 Decimal) Decimal

func (Decimal) AddFloat64

func (d Decimal) AddFloat64(n float64) Decimal

func (Decimal) AddInt

func (d Decimal) AddInt(n int) Decimal

func (Decimal) BitsAfterDecimalPoint

func (d Decimal) BitsAfterDecimalPoint() int

func (Decimal) Div

func (d Decimal) Div(d2 Decimal) Decimal

func (Decimal) DivFloat64

func (d Decimal) DivFloat64(n float64) Decimal

func (Decimal) DivInt

func (d Decimal) DivInt(n int) Decimal

func (Decimal) DivRound

func (d Decimal) DivRound(d2 Decimal, precision int) Decimal

FIXME: 这个是RoundUp还是RoundDown?

func (Decimal) DivRoundDown

func (d Decimal) DivRoundDown(d2 Decimal, precision int) Decimal

func (Decimal) DivRoundFloat64

func (d Decimal) DivRoundFloat64(d2 float64, precision int) Decimal

func (Decimal) DivRoundInt

func (d Decimal) DivRoundInt(d2 int, precision int) Decimal

func (Decimal) Equal

func (d Decimal) Equal(cmp Decimal) bool

func (Decimal) EqualFloat64

func (d Decimal) EqualFloat64(cmp float64) bool

func (Decimal) EqualInt

func (d Decimal) EqualInt(cmp int) bool

func (Decimal) Float64

func (d Decimal) Float64() float64

func (Decimal) Float64Ex

func (d Decimal) Float64Ex() (val float64, exact bool)

func (Decimal) GreaterThan

func (d Decimal) GreaterThan(cmp Decimal) bool

func (Decimal) GreaterThanFloat64

func (d Decimal) GreaterThanFloat64(cmp float64) bool

func (Decimal) GreaterThanInt

func (d Decimal) GreaterThanInt(cmp int) bool

func (Decimal) GreaterThanOrEqual

func (d Decimal) GreaterThanOrEqual(cmp Decimal) bool

func (Decimal) GreaterThanOrEqualFloat64

func (d Decimal) GreaterThanOrEqualFloat64(cmp float64) bool

func (Decimal) GreaterThanOrEqualInt

func (d Decimal) GreaterThanOrEqualInt(cmp int) bool

func (Decimal) Int64Part

func (d Decimal) Int64Part() int64

func (Decimal) IntPart

func (d Decimal) IntPart() int

func (Decimal) IsNegative

func (d Decimal) IsNegative() bool

func (Decimal) IsPositive

func (d Decimal) IsPositive() bool

func (Decimal) IsZero

func (d Decimal) IsZero() bool

func (Decimal) LessThan

func (d Decimal) LessThan(cmp Decimal) bool

func (Decimal) LessThanFloat64

func (d Decimal) LessThanFloat64(cmp float64) bool

func (Decimal) LessThanInt

func (d Decimal) LessThanInt(cmp int) bool

func (Decimal) LessThanOrEqual

func (d Decimal) LessThanOrEqual(cmp Decimal) bool

func (Decimal) LessThanOrEqualFloat64

func (d Decimal) LessThanOrEqualFloat64(cmp float64) bool

func (Decimal) LessThanOrEqualInt

func (d Decimal) LessThanOrEqualInt(cmp int) bool

func (Decimal) MarshalBSONValue

func (d Decimal) MarshalBSONValue() (bsontype.Type, []byte, error)

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 (d Decimal) MarshalBinary() (data []byte, err error)

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

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

func (d Decimal) MarshalJSONWithoutQuotes() ([]byte, error)

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 (d Decimal) MarshalText() (text []byte, err error)

func (Decimal) Mul

func (d Decimal) Mul(d2 Decimal) Decimal

func (Decimal) MulFloat64

func (d Decimal) MulFloat64(n float64) Decimal

func (Decimal) MulInt

func (d Decimal) MulInt(n int) Decimal

func (*Decimal) SetFloat64

func (d *Decimal) SetFloat64(val float64)

func (*Decimal) SetInt

func (d *Decimal) SetInt(val int)

func (Decimal) String

func (d Decimal) String() string

func (Decimal) Sub

func (d Decimal) Sub(d2 Decimal) Decimal

func (Decimal) SubFloat64

func (d Decimal) SubFloat64(n float64) Decimal

func (Decimal) SubInt

func (d Decimal) SubInt(n int) Decimal

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

func (Decimal) Trunc

func (d Decimal) Trunc(prec int, step float64) Decimal

prec就是小数点后最多支持多少位

func (Decimal) Trunc2

func (d Decimal) Trunc2(min Decimal, step float64) Decimal

min 就是小数点后最多多少位的小数写法,比如,min=0.00001,prec就是5

func (Decimal) TurnPositiveNegative

func (d Decimal) TurnPositiveNegative() Decimal

func (*Decimal) UnmarshalBSONValue

func (d *Decimal) UnmarshalBSONValue(t bsontype.Type, data []byte) error

func (*Decimal) UnmarshalBinary

func (d *Decimal) UnmarshalBinary(b []byte) error

func (*Decimal) UnmarshalJSON

func (d *Decimal) UnmarshalJSON(b []byte) error

func (*Decimal) UnmarshalText

func (d *Decimal) UnmarshalText(text []byte) error

func (Decimal) WithPrec

func (d Decimal) WithPrec(prec int) Decimal

Jump to

Keyboard shortcuts

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