pkgdecimal

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decimal

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

Decimal is an arbitrary-precision decimal.

func FromFloat64 added in v0.0.4

func FromFloat64(f float64) (Decimal, error)

FromFloat64 creates a new Decimal from a float64.

func FromStr

func FromStr(str string) (Decimal, error)

FromStr creates a new Decimal from a string.

func MustFromStr

func MustFromStr(str string) Decimal

MustFromStr creates a new Decimal from a string. It panics if the string is not a valid decimal.

func NewFromInt

func NewFromInt(i int64) Decimal

NewFromInt creates a new Decimal from an int64.

func (Decimal) Add

func (d Decimal) Add(d2 Decimal) Decimal

Add adds two decimals and returns the result.

func (Decimal) Cmp

func (d Decimal) Cmp(d2 Decimal) int

Cmp compares two decimals and returns: -1 if d < d2 0 if d == d2 1 if d > d2

func (Decimal) Div

func (d Decimal) Div(d2 Decimal) Decimal

Div divides current decimal by a given one and returns the result.

func (Decimal) Equal

func (d Decimal) Equal(d2 Decimal) bool

Equal returns true if d == d2.

func (Decimal) Float64 added in v0.0.3

func (d Decimal) Float64() (float64, error)

Float64 returns the float64 representation of the decimal.

func (Decimal) Greater added in v0.0.3

func (d Decimal) Greater(d2 Decimal) bool

Greater returns true if d > d2.

func (Decimal) GreaterOrEqual added in v0.0.3

func (d Decimal) GreaterOrEqual(d2 Decimal) bool

GreaterOrEqual returns true if d >= d2.

func (Decimal) InRange

func (d Decimal) InRange(min, max Decimal) bool

InRange returns true if d is in the range [min, max].

func (Decimal) InRangeInt

func (d Decimal) InRangeInt(min, max int64) bool

InRangeInt returns true if d is in the range [min, max].

func (*Decimal) IsNegative

func (d *Decimal) IsNegative() bool

IsNegative returns true if d < 0.

func (Decimal) IsZero

func (d Decimal) IsZero() bool

IsZero returns true if d == 0.

func (Decimal) Less added in v0.0.3

func (d Decimal) Less(d2 Decimal) bool

Less returns true if d < d2.

func (Decimal) LessOrEqual added in v0.0.3

func (d Decimal) LessOrEqual(d2 Decimal) bool

LessOrEqual returns true if d <= d2.

func (Decimal) MarshalText

func (d Decimal) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Decimal) Mul

func (d Decimal) Mul(d2 Decimal) Decimal

Mul multiplies two decimals and returns the result.

func (Decimal) MulInt

func (d Decimal) MulInt(i int64) Decimal

MulInt multiplies a decimal by an int64 and returns the result.

func (Decimal) MustFloat64 added in v0.0.3

func (d Decimal) MustFloat64() float64

MustFloat64 returns the float64 representation of the decimal. It panics if the decimal can't be converted to float64.

func (Decimal) Reduce

func (d Decimal) Reduce() Decimal

Reduce removes all the trailing zeroes from the decimal.

func (Decimal) Round

func (d Decimal) Round(n int) Decimal

Round rounds the decimal to n digits after 0.

func (*Decimal) RoundOrNil

func (d *Decimal) RoundOrNil(n int) *Decimal

RoundOrNil returns nil if the Decimal is nil or rounds it to n digits after 0.

func (*Decimal) Scan

func (d *Decimal) Scan(src interface{}) error

Scan implements sql.Scanner.

func (Decimal) String

func (d Decimal) String() string

String returns the string representation of the decimal.

func (Decimal) Sub

func (d Decimal) Sub(d2 Decimal) Decimal

Sub subtracts two decimals and returns the result.

func (*Decimal) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Decimal) UnmarshalText

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

UnmarshalText implements encoding.TextUnmarshaler.

func (Decimal) Value

func (d Decimal) Value() (driver.Value, error)

Value implements driver.Valuer.

Jump to

Keyboard shortcuts

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