decimal

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

README

#Go-Decimal

The go-decimal package providers a Decimal type for multi-precision arithmetic.

##Usage

  • create a Decimal instance by float64 or int64:

      dec := decimal.New(5.18)
    
      dec := new(decimal.Decimal).SetFloat(5.18)
    
      dec := new(decimal.Decimal).SetInt(5)
    
  • create a Decimal instance by string:

      dec, err := decimal.Parse("5.18181818181818181818181818181818181818")
    
      dec, err := new(decimal.Decimal).SetString("5.18181818181818181818181818181818181818")
    

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 represents a decimal which can handing fixed precision.

func New

func New(number float64) *Decimal

New returns a new instance of Decimal.

func Parse

func Parse(numberString string) (*Decimal, error)

Parse returns a new instance of Decimal by parse decimal string.

func (*Decimal) Add

func (this *Decimal) Add(another *Decimal) *Decimal

Add sets this to the sum of this and another and returns this.

func (*Decimal) Cmp

func (this *Decimal) Cmp(another *Decimal) int

Cmp compares this and another and returns: -1 if this < another

0 if this == another

+1 if this > another

func (*Decimal) Div added in v1.0.0

func (this *Decimal) Div(another *Decimal) *Decimal

Div sets this to the quotient this/another and return this.

func (Decimal) Float added in v1.0.0

func (this Decimal) Float() float64

Float returns the nearest float value of decimal.

func (Decimal) FloatString

func (this Decimal) FloatString(precision int) string

FloatString returns a string representation of decimal form with precision digits of precision after the decimal point and the last digit rounded.

func (*Decimal) Mul

func (this *Decimal) Mul(another *Decimal) *Decimal

Mul sets this to the product this*another and returns this.

func (*Decimal) SetFloat added in v1.0.0

func (this *Decimal) SetFloat(v float64) *Decimal

SetFloat sets this to v and returns this.

func (*Decimal) SetInt added in v1.0.0

func (this *Decimal) SetInt(v int64) *Decimal

SetInt sets this to v and returns this.

func (*Decimal) SetString added in v1.0.0

func (this *Decimal) SetString(v string) (*Decimal, error)

SetInt sets this to the valud of v and returns this.

func (Decimal) Sign

func (this Decimal) Sign() int

Sign returns: -1: if this < 0

0: if this == 0

+1: if this > 0

func (Decimal) String

func (this Decimal) String() string

String returns the string of Decimal.

func (*Decimal) Sub

func (this *Decimal) Sub(another *Decimal) *Decimal

Sub sets this to the difference this-another and returns this.

Jump to

Keyboard shortcuts

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