Documentation
¶
Overview ¶
Package decimal extends govalues decimals with canonical presentation and Money. Values use 19-digit half-even rounding; arithmetic retains Commons result types.
Code generated by internal/gendecimal; DO NOT EDIT.
Index ¶
- Constants
- Variables
- type Decimal
- func Mean(d ...Decimal) (Decimal, error)
- func MustNew(value int64, scale int) Decimal
- func MustParse(s string) Decimal
- func New(value int64, scale int) (Decimal, error)
- func NewFromFloat64(f float64) (Decimal, error)
- func NewFromInt64(whole int64, frac int64, scale int) (Decimal, error)
- func Parse(s string) (Decimal, error)
- func ParseExact(s string, scale int) (Decimal, error)
- func Prod(d ...Decimal) (Decimal, error)
- func Sum(d ...Decimal) (Decimal, error)
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(e Decimal) (Decimal, error)
- func (d Decimal) AddExact(e Decimal, scale int) (Decimal, error)
- func (d Decimal) AddMul(e Decimal, f Decimal) (Decimal, error)
- func (d Decimal) AddMulExact(e Decimal, f Decimal, scale int) (Decimal, error)
- func (d Decimal) AddQuo(e Decimal, f Decimal) (Decimal, error)
- func (d Decimal) AddQuoExact(e Decimal, f Decimal, scale int) (Decimal, error)
- func (d Decimal) AppendText(dst []byte) ([]byte, error)
- func (d Decimal) Ceil(scale int) Decimal
- func (d Decimal) Clamp(min Decimal, max Decimal) (Decimal, error)
- func (d Decimal) Cmp(e Decimal) int
- func (d Decimal) CmpAbs(e Decimal) int
- func (d Decimal) CmpTotal(e Decimal) int
- func (d Decimal) Coef() uint64
- func (d Decimal) Compare(other Decimal) int
- func (d Decimal) CopySign(e Decimal) Decimal
- func (d Decimal) Equal(e Decimal) bool
- func (d Decimal) Exp() (Decimal, error)
- func (d Decimal) Expm1() (Decimal, error)
- func (d Decimal) Float64() (float64, bool)
- func (d Decimal) Floor(scale int) Decimal
- func (d Decimal) Format(state fmt.State, verb rune)
- func (d Decimal) Int64(scale int) (int64, int64, bool)
- func (d Decimal) Inv() (Decimal, error)
- func (d Decimal) IsInt() bool
- func (d Decimal) IsNeg() bool
- func (d Decimal) IsOne() bool
- func (d Decimal) IsPos() bool
- func (d Decimal) IsZero() bool
- func (d Decimal) Less(e Decimal) bool
- func (d Decimal) Log() (Decimal, error)
- func (d Decimal) Log1p() (Decimal, error)
- func (d Decimal) Log2() (Decimal, error)
- func (d Decimal) Log10() (Decimal, error)
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) MarshalText() ([]byte, error)
- func (d Decimal) Max(e Decimal) Decimal
- func (d Decimal) Min(e Decimal) Decimal
- func (d Decimal) MinScale() int
- func (d Decimal) Mul(e Decimal) (Decimal, error)
- func (d Decimal) MulExact(e Decimal, scale int) (Decimal, error)
- func (d Decimal) Neg() Decimal
- func (d Decimal) One() Decimal
- func (d Decimal) Pad(scale int) Decimal
- func (d Decimal) Pow(e Decimal) (Decimal, error)
- func (d Decimal) PowInt(power int) (Decimal, error)
- func (d Decimal) Prec() int
- func (d Decimal) Quantize(e Decimal) Decimal
- func (d Decimal) Quo(e Decimal) (Decimal, error)
- func (d Decimal) QuoExact(e Decimal, scale int) (Decimal, error)
- func (d Decimal) QuoRem(e Decimal) (Decimal, Decimal, error)
- func (d Decimal) Rescale(scale int) Decimal
- func (d Decimal) Round(scale int) Decimal
- func (d Decimal) SameScale(e Decimal) bool
- func (d Decimal) Scale() int
- func (d Decimal) Sign() int
- func (d Decimal) Sqrt() (Decimal, error)
- func (d Decimal) String() string
- func (d Decimal) Sub(e Decimal) (Decimal, error)
- func (d Decimal) SubAbs(e Decimal) (Decimal, error)
- func (d Decimal) SubExact(e Decimal, scale int) (Decimal, error)
- func (d Decimal) SubMul(e Decimal, f Decimal) (Decimal, error)
- func (d Decimal) SubMulExact(e Decimal, f Decimal, scale int) (Decimal, error)
- func (d Decimal) SubQuo(e Decimal, f Decimal) (Decimal, error)
- func (d Decimal) SubQuoExact(e Decimal, f Decimal, scale int) (Decimal, error)
- func (d Decimal) Trim(scale int) Decimal
- func (d Decimal) Trunc(scale int) Decimal
- func (d Decimal) ULP() Decimal
- func (d *Decimal) UnmarshalJSON(data []byte) error
- func (d *Decimal) UnmarshalText(data []byte) error
- func (d Decimal) WithinOne() bool
- func (d Decimal) Zero() Decimal
- type Money
- type MoneyOptions
Examples ¶
Constants ¶
View Source
const MaxPrec = upstream.MaxPrec
View Source
const MaxScale = upstream.MaxScale
View Source
const MinScale = upstream.MinScale
Variables ¶
View Source
var One = Decimal{upstream.One}
View Source
var Zero = Decimal{upstream.Zero}
Functions ¶
This section is empty.
Types ¶
type Decimal ¶
func NewFromFloat64 ¶
func (Decimal) Add ¶
Example ¶
package main
import (
"fmt"
"github.com/flanksource/commons/bigdecimal"
"github.com/flanksource/commons/decimal"
)
func main() {
total, err := decimal.MustParse("1.20").Add(decimal.MustParse("0.03"))
if err != nil {
panic(err)
}
fmt.Printf("%s %.3f\n", total, total)
fmt.Println(bigdecimal.MustParse("9007199254740993.0000000001"))
}
Output: 1.23 1.230 9007199254740993.0000000001
func (Decimal) AddMulExact ¶
func (Decimal) AddQuoExact ¶
func (Decimal) MarshalJSON ¶
func (Decimal) MarshalText ¶
func (Decimal) SubMulExact ¶
func (Decimal) SubQuoExact ¶
func (*Decimal) UnmarshalJSON ¶
func (*Decimal) UnmarshalText ¶
type Money ¶
func NewMoney ¶
func NewMoney(opts MoneyOptions) (Money, error)
Example ¶
package main
import (
"fmt"
"github.com/flanksource/commons/decimal"
)
func main() {
premium, err := decimal.NewMoney(decimal.MoneyOptions{Amount: "125", Currency: "USD", DecimalPlaces: 2})
if err != nil {
panic(err)
}
fmt.Println(premium)
fmt.Println(premium.Amount())
}
Output: USD 125.00 125
type MoneyOptions ¶
Click to show internal directories.
Click to hide internal directories.