Documentation ¶
Index ¶
- Constants
- func DecsEqual(d1s, d2s []Dec) bool
- type Dec
- func MaxDec(d1, d2 Dec) Dec
- func MinDec(d1, d2 Dec) Dec
- func MustNewDecFromStr(s string) Dec
- func NewDec(i int64) Dec
- func NewDecFromBigInt(i *big.Int) Dec
- func NewDecFromBigIntWithPrec(i *big.Int, prec int64) Dec
- func NewDecFromInt(i *big.Int) Dec
- func NewDecFromIntWithPrec(i *big.Int, prec int64) Dec
- func NewDecFromStr(str string) (d Dec, err error)
- func NewDecWithPrec(i, prec int64) Dec
- func OneDec() Dec
- func SmallestDec() Dec
- func ZeroDec() Dec
- func (d Dec) Abs() Dec
- func (d Dec) Add(d2 Dec) Dec
- func (d Dec) Ceil() Dec
- func (d Dec) Copy() Dec
- func (d Dec) Equal(d2 Dec) bool
- func (d Dec) Format(s fmt.State, verb rune)
- func (d Dec) GT(d2 Dec) bool
- func (d Dec) GTE(d2 Dec) bool
- func (d Dec) IsInteger() bool
- func (d Dec) IsNegative() bool
- func (d Dec) IsNil() bool
- func (d Dec) IsPositive() bool
- func (d Dec) IsZero() bool
- func (d Dec) LT(d2 Dec) bool
- func (d Dec) LTE(d2 Dec) bool
- func (d Dec) MarshalJSON() ([]byte, error)
- func (d Dec) MarshalYAML() (interface{}, error)
- func (d Dec) Mul(d2 Dec) Dec
- func (d Dec) MulInt(i *big.Int) Dec
- func (d Dec) MulInt64(i int64) Dec
- func (d Dec) MulTruncate(d2 Dec) Dec
- func (d Dec) Neg() Dec
- func (d Dec) Quo(d2 Dec) Dec
- func (d Dec) QuoInt(i *big.Int) Dec
- func (d Dec) QuoInt64(i int64) Dec
- func (d Dec) QuoRoundUp(d2 Dec) Dec
- func (d Dec) QuoTruncate(d2 Dec) Dec
- func (d Dec) RoundInt() *big.Int
- func (d Dec) RoundInt64() int64
- func (d Dec) String() string
- func (d Dec) Sub(d2 Dec) Dec
- func (d Dec) TruncateDec() Dec
- func (d Dec) TruncateInt() *big.Int
- func (d Dec) TruncateInt64() int64
- func (d *Dec) UnmarshalJSON(bz []byte) error
Constants ¶
const ( Precision = 18 // bytes required to represent the above precision // Ceiling[Log2[999 999 999 999 999 999]] DecimalPrecisionBits = 60 )
number of decimal places
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dec ¶
Dec represent a decimal. NOTE: never use new(Dec) or else we will panic unmarshalling into the nil embedded big.Int
func MustNewDecFromStr ¶
MustNewDecFromStr Decimal from string, panic on error
func NewDecFromBigInt ¶
NewDecFromBigInt creates a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision
func NewDecFromBigIntWithPrec ¶
NewDecFromBigIntWithPrec creates a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision
func NewDecFromInt ¶
NewDecFromInt creates a new Dec from big integer assuming whole numbers CONTRACT: prec <= Precision
func NewDecFromIntWithPrec ¶
NewDecFromIntWithPrec creates a new Dec from big integer with decimal place at prec CONTRACT: prec <= Precision
func NewDecFromStr ¶
NewDecFromStr creates a decimal from an input decimal string. valid must come in the form:
(-) whole integers (.) decimal integers
examples of acceptable input include:
-123.456 456.7890 345 -456789
NOTE - An error will return if more decimal places are provided in the string than the constant Precision.
CONTRACT - This function does not mutate the input str.
func NewDecWithPrec ¶
NewDecWithPrec creates a new Dec from integer with decimal place at prec CONTRACT: prec <= Precision
func (Dec) Ceil ¶
Ceil returns the smallest interger value (as a decimal) that is greater than or equal to the given decimal.
func (Dec) MarshalJSON ¶
MarshalJSON marshals the decimal
func (Dec) MarshalYAML ¶
MarshalYAML returns Ythe AML representation.
func (Dec) RoundInt64 ¶
RoundInt64 rounds the decimal using bankers rounding
func (Dec) TruncateDec ¶
TruncateDec truncates the decimals from the number and returns a Dec
func (Dec) TruncateInt ¶
TruncateInt truncates the decimals from the number and returns an Int
func (Dec) TruncateInt64 ¶
TruncateInt64 truncates the decimals from the number and returns an int64
func (*Dec) UnmarshalJSON ¶
UnmarshalJSON defines custom decoding scheme