Documentation
¶
Index ¶
- Variables
- type Decimal
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(d2 Decimal) Decimal
- func (d Decimal) Ceil() Decimal
- func (d Decimal) Cmp(d2 Decimal) int
- func (d Decimal) Div(d2 Decimal) Decimal
- func (d Decimal) EQ(d2 Decimal) bool
- func (d Decimal) Float() float64
- func (d Decimal) Floor() Decimal
- func (d Decimal) FormattedString(precision int) string
- func (d Decimal) Frac() Decimal
- func (d Decimal) GT(d2 Decimal) bool
- func (d Decimal) GTE(d2 Decimal) bool
- func (d Decimal) IsNegative() bool
- func (d Decimal) IsPositive() bool
- func (d Decimal) IsZero() bool
- func (d Decimal) LT(d2 Decimal) bool
- func (d Decimal) LTE(d2 Decimal) bool
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) Max(d2 Decimal) Decimal
- func (d Decimal) Min(d2 Decimal) Decimal
- func (d Decimal) Mul(d2 Decimal) Decimal
- func (d Decimal) Neg() Decimal
- func (d Decimal) Pow(y int) Decimal
- func (d Decimal) PowFloat(y float64) Decimal
- func (d Decimal) Round() Decimal
- func (d Decimal) Sign() int
- func (d Decimal) Sqrt() Decimal
- func (d Decimal) String() string
- func (d Decimal) Sub(d2 Decimal) Decimal
- func (d Decimal) Truncate() Decimal
- func (d *Decimal) UnmarshalJSON(data []byte) error
- func (d Decimal) Zero() bool
Constants ¶
This section is empty.
Variables ¶
var ( // ZERO is a Decimal with value 0 ZERO = New(0) // ONE is a Decimal with value 1 ONE = New(1) )
Functions ¶
This section is empty.
Types ¶
type Decimal ¶
type Decimal struct {
// contains filtered or unexported fields
}
Decimal represents a high-precision decimal number. It wraps math/big.Float to provide convenient methods for financial calculations.
func NewFromBigFloat ¶
NewFromBigFloat creates a new Decimal from a big.Float
func NewFromString ¶
NewFromString creates a new Decimal from a string. It panics if string is not a valid number.
func NewFromStringWithError ¶
NewFromStringWithError creates a new Decimal from a string. Returns error if string is not a valid number.
func (Decimal) FormattedString ¶
FormattedString returns string representation of d with fixed precision
func (Decimal) MarshalJSON ¶ added in v0.0.7
MarshalJSON implements json.Marshaler by serializing the decimal as a string.
func (Decimal) Round ¶
Round returns d rounded to the nearest integer, with ties rounding away from zero
func (*Decimal) UnmarshalJSON ¶ added in v0.0.7
UnmarshalJSON implements json.Unmarshaler by parsing a string or number.