decimal

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Zero = MustNew("0")

Zero is 0 as a Decimal.

Functions

This section is empty.

Types

type Decimal

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

Decimal represents a fixed-point decimal with an integer and fraction part. MySQL allows a DECIMAL-type to have 1 to 65 digits, with the scale or fraction having 0 to 30 digits. Both the integral and fraction part are therefor stored as big.Int. This Decimal-type is just storage. The caller can access the integral and fraction part through the methods Integral() and Fraction(). There are no methods to do calculations.

func MustNew

func MustNew(s string) *Decimal

MustNew is similar to New but instead of return the error, it panics.

func New

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

New takes string s as decimal (for example "3.14"), and stores the integer and fraction in a newly instantiated Decimal object. Only base 10 is supported, so no `0x` prefixes for example. The call is responsible to remove any thousand separators.

func NewDecimalFromBCD

func NewDecimalFromBCD(bcd []byte) (*Decimal, error)

NewDecimalFromBCD decodes bcd or Binary-Coded Decimal and returns a new instance of Decimal.

func (*Decimal) Encode

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

Encode will encode d as Binary-Coded Decimal (BCD), making it ready to send it to MySQL.

func (*Decimal) Equal

func (d *Decimal) Equal(other *Decimal) bool

Equal returns whether d is equal to the other.

func (*Decimal) Fraction

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

Fraction returns the fraction part of d.

func (*Decimal) Integral

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

Integral returns the integer part of d.

func (*Decimal) Sign

func (d *Decimal) Sign() int

Sign returns the sign information of the integer part of d:

-1 if x <  0
 0 if x == 0
+1 if x >  0

func (*Decimal) String

func (d *Decimal) String() string

String returns the textual representation of Decimal as decimal number with a dot '.' as separator.

Jump to

Keyboard shortcuts

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