Help us shape the future of Go! Take the 2026 Go Developer Survey

decimal

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

README

Golang Decimal Package

Golang Decimal Package providers a decimal type for multi-precision arithmetic.

Usage

  • create a decimal by float64:

      dec := decimal.New(5.18)
    
  • create a decimal by string:

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

Copyright 2014 Landjur, Inc. Code released under the Apache License, Version 2.0.

Documentation

Overview

Package decimal providers a Decimal type for multi-precision arithmetic.

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) Float64

func (this Decimal) Float64() float64

Float64 returns the nearest float64 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) 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