decimal

package
v0.0.0-...-bc49051 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 2 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 int64

Decimal is a fixed precision number with (4) digits of precision.

It blends the benefits of an arbitrary precision type (e.g. math.big) with the performance of register types for common operations.

Addition and subtraction can be done directly on values with the builtin operators. For everything else, there are helper functions on the type itself.

func New

func New(v any) Decimal

New returns a new decimal.

func (Decimal) Abs

func (d Decimal) Abs() Decimal

Abs returnst the absolute value of the decimal.

It is equivalent to -d if d < 0.

func (Decimal) Add

func (d Decimal) Add(v Decimal) Decimal

Add adds this decimal to a given decimal.

It is equivalent to d + v.

func (Decimal) Div

func (d Decimal) Div(v Decimal) Decimal

Div divides this decimal by a given decimal.

It is equivalent to d / v.

func (Decimal) Float64

func (d Decimal) Float64() float64

Float64 returns a float64 for the given decimal value.

func (Decimal) Invert

func (d Decimal) Invert() Decimal

Invert inverts the value of this decimal.

It is equivalent to 1/d.

func (Decimal) MarshalJSON

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

MarshalJSON marshals the decimal as a json.

func (Decimal) Mul

func (d Decimal) Mul(v Decimal) Decimal

Mul multiplies this decimal by a given decimal.

It is equivalent to d * v.

func (Decimal) Neg

func (d Decimal) Neg() Decimal

Neg inverts the sign of this decimal.

It is equivalent to -d.

func (*Decimal) Set

func (d *Decimal) Set(v float64)

Set sets the decimal value.

func (*Decimal) String

func (d *Decimal) String() string

String returns a string representation of the decimal.

func (Decimal) Sub

func (d Decimal) Sub(v Decimal) Decimal

Sub subtracts this decimal from a given decimal.

It is equivalent to d - v.

Jump to

Keyboard shortcuts

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