Documentation ¶
Overview ¶
Package implements a fixed-point decimal
Index ¶
- type Decimal
- func (d *Decimal) Abs() *Decimal
- func (d *Decimal) Add(d2 *Decimal) *Decimal
- func (d *Decimal) Cmp(d2 *Decimal) int
- func (d *Decimal) Div(d2 *Decimal) *Decimal
- func (d *Decimal) FormattedString() string
- func (d *Decimal) Mul(d2 *Decimal) *Decimal
- func (d *Decimal) Scale() int
- func (d *Decimal) String() string
- func (d *Decimal) StringScaled(scale int) string
- func (d *Decimal) Sub(d2 *Decimal) *Decimal
- type MovingAverage
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 fixed-point decimal.
func NewFromFloat ¶ added in v1.0.2
func NewFromString ¶
NewFromString returns a new fixed-point decimal based on the given string
func (*Decimal) Cmp ¶
Cmp compares x and y and returns -1, 0 or 1
Example ¶
-1 if x < y 0 if x == y +1 if x > y
func (*Decimal) FormattedString ¶
String returns the string representatino of the decimal with the fixed point
Example:
d := New(-12345, -3) println(d.String())
Output:
-12.345
func (*Decimal) String ¶
String returns the string representatino of the decimal
Example:
d := New(-12345, -3) println(d.String())
Output:
-12345
func (*Decimal) StringScaled ¶
StringScaled first scales the decimal then calls .String() on it.
type MovingAverage ¶ added in v1.1.0
type MovingAverage struct {
// contains filtered or unexported fields
}
func NewMovingAverage ¶ added in v1.1.0
func NewMovingAverage(capacity int, scale int) *MovingAverage
func (*MovingAverage) Append ¶ added in v1.1.0
func (ma *MovingAverage) Append(sample *Decimal)
func (*MovingAverage) Calculate ¶ added in v1.1.0
func (ma *MovingAverage) Calculate() *Decimal
func (*MovingAverage) Capacity ¶ added in v1.1.0
func (ma *MovingAverage) Capacity() int
func (*MovingAverage) Size ¶ added in v1.1.0
func (ma *MovingAverage) Size() int
Click to show internal directories.
Click to hide internal directories.