decimal

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultIncrement = 1

Default increment for integer constructors.

View Source
const DefaultScale = 12

Default decimal points set for integer constructors.

Variables

This section is empty.

Functions

func BankersRound

func BankersRound(value *big.Int, scale *big.Int) *big.Int

Types

type Decimal

type Decimal struct {
	// contains filtered or unexported fields
}

Decimal implements fixed-point arithmetic.

func NewFromBigFloat

func NewFromBigFloat(f *big.Float) *Decimal

NewFromBigFloat creates a new Decimal object from a big.Float.

func NewFromBigInt

func NewFromBigInt(bi *big.Int) *Decimal

NewFromBigInt creates a new Decimal object from a big.Int.

func NewFromFloat64

func NewFromFloat64(f float64) *Decimal

NewFromFloat64 creates a new Decimal object from a float64.

func NewFromInt64

func NewFromInt64(i int64) *Decimal

NewFromInt64 creates a new Decimal object from an int64.

func NewFromString

func NewFromString(s string) (*Decimal, error)

NewFromString creates a new Decimal object from a string.

func (*Decimal) Abs

func (d *Decimal) Abs() *Decimal

Abs returns the absolute value of d.

func (*Decimal) Add

func (x *Decimal) Add(y *Decimal) *Decimal

Add returns the result of x + y.

func (*Decimal) Cmp

func (x *Decimal) Cmp(y *Decimal) int

Cmp compares x to y (-1, 0, 1 for <, =, >).

func (*Decimal) Copy

func (d *Decimal) Copy() *Decimal

Copy creates a copy of m.

func (*Decimal) Div

func (x *Decimal) Div(y *Decimal) *Decimal

Div returns the result of x / y.

func (*Decimal) Float64

func (d *Decimal) Float64() float64

Float64 returns the floating point representation of m with potential loss of precision.

func (*Decimal) GetIncrement

func (d *Decimal) GetIncrement() int64

GetIncrement returns the smallest allowable unit for the decimal value.

func (*Decimal) GetScale

func (d *Decimal) GetScale() int64

GetScale returns the number of decimal points.

func (*Decimal) GetSmallestIncrement

func (d *Decimal) GetSmallestIncrement() *Decimal

GetSmallestIncrement returns the smallest possible increment of d.

func (*Decimal) Int64

func (d *Decimal) Int64() int64

Int64 returns the integer part of m with truncated decimals.

func (*Decimal) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (*Decimal) Mul

func (x *Decimal) Mul(y *Decimal) *Decimal

Mul returns the result of x * y

func (*Decimal) OffsetPercent

func (d *Decimal) OffsetPercent(o *Decimal) *Decimal

OffsetPercent returns the adjustment of d by %o. Formula: m * (1 + o). The multiplicand decimals are set to the max precision of both d and o.

func (*Decimal) OffsetTicks

func (d *Decimal) OffsetTicks(o *Decimal) *Decimal

OffsetTicks returns the adjustment of m by an increment proportional to o.

func (*Decimal) Pow

func (x *Decimal) Pow(y *Decimal) *Decimal

Pow returns x ** y.

func (*Decimal) Rat

func (d *Decimal) Rat() *big.Rat

Rat returns the rational number of m.

func (*Decimal) RawBigInt

func (d *Decimal) RawBigInt() *big.Int

RawBigInt returns the raw integer representation in the form of big.Int.

func (*Decimal) ScalingFactor

func (d *Decimal) ScalingFactor() *big.Int

ScalingFactor returns 10 ^ decimals in big.Int.

func (*Decimal) SetIncrement

func (d *Decimal) SetIncrement(increment int64) *Decimal

SetIncrement sets the smallest allowable unit of d.

func (*Decimal) SetRounding

func (d *Decimal) SetRounding(rounding RoundingFunction) *Decimal

func (*Decimal) SetScale

func (d *Decimal) SetScale(scale int64) *Decimal

SetScale returns m with adjusted decimal places.

func (*Decimal) SetSize

func (d *Decimal) SetSize(size *Decimal) *Decimal

SetSize ensures the value of d is always a multiple of the specified.

func (*Decimal) Sign

func (d *Decimal) Sign() int

Sign returns -1 if d < 0, 0 if d == 0, and +1 if d > 0.

func (*Decimal) String

func (d *Decimal) String() string

String returns the literal representation of m.

func (*Decimal) Sub

func (x *Decimal) Sub(y *Decimal) *Decimal

Sub returns the result of x - y

func (*Decimal) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

type RoundingFunction

type RoundingFunction func(value *big.Int, scale *big.Int) *big.Int

Jump to

Keyboard shortcuts

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