Documentation ¶
Index ¶
- type Decimal
- func (d Decimal) Add(other Decimal) Decimal
- func (d Decimal) AddToScale(other Decimal, scale int) Decimal
- func (d Decimal) Cmp(other Decimal) int
- func (d Decimal) Div(other Decimal) Decimal
- func (d Decimal) DivToScale(other Decimal, scale int) Decimal
- func (d Decimal) EQ(other Decimal) bool
- func (d Decimal) Float64() float64
- func (d Decimal) GT(other Decimal) bool
- func (d Decimal) GTE(other Decimal) bool
- func (d Decimal) GetBSON() (interface{}, error)
- func (d Decimal) GoString() string
- func (d Decimal) Int64() int64
- func (d Decimal) IsZero() bool
- func (d Decimal) LT(other Decimal) bool
- func (d Decimal) LTE(other Decimal) bool
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) Mul(other Decimal) Decimal
- func (d Decimal) MulToScale(other Decimal, scale int) Decimal
- func (d Decimal) NE(other Decimal) bool
- func (d Decimal) Neg() Decimal
- func (d Decimal) Round(scale int) Decimal
- func (d Decimal) Scale() uint8
- func (d *Decimal) SetBSON(raw bson.Raw) error
- func (d Decimal) ShortString() string
- func (d Decimal) Sign() int
- func (d Decimal) String() string
- func (d Decimal) Sub(other Decimal) Decimal
- func (d Decimal) SubToScale(other Decimal, scale int) Decimal
- func (d Decimal) ToDecimal128() (low, high uint64)
- func (d *Decimal) UnmarshalJSON(buf []byte) error
- func (d Decimal) Value() (driver.Value, error)
- type NullDecimal
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 is a decimal implementation provides 18 max effective numbers. Decimal is immutable after creation, passed by value. Do not change its fields.
func FromDecimal128 ¶
FromDecimal128 convert IEEE 754 decimal128 to Decimal. Decimal128 has greater range than Decimal, FromDecimal128 expect the argument must in range of Decimal.
func FromString ¶
FromString create decimal from string, scale set from fragment part of number. Such as '3.00', scale is 2.
func FromStringWithScale ¶
FromStringWithScale create decimal from string, with specific scale. Use number's actual scale if it larger than specific scale. Examples:
FromStringWithScale("3", 2) // 3.00 FromStringWithScale("3.33", 0) // 3.33
func (Decimal) Add ¶
Add this value with other value, use two values' highest scale as result scale, such as 3.45 + 1 = 4.45.
func (Decimal) AddToScale ¶
AddToScale this value with other value round to specific scale.
func (Decimal) Cmp ¶
Cmp the other value return -1 if < other, 1 if > other, 0 if equal. Cmp ignore scale, so 0.00 equals to 0
func (Decimal) DivToScale ¶
DivToScale the other value and round result to specific scale.
func (Decimal) GetBSON ¶
GetBSON implement bson.Getter interface, marshal value to mongoDB. Marshal to string to pressure both scale and value.
func (Decimal) GoString ¶
GoString implement fmt.GoStringer interface. Adding 'm' suffix to result of String().
func (Decimal) MarshalJSON ¶
func (Decimal) MulToScale ¶
MulToScale multiply the other value and round to specific scale
func (Decimal) ShortString ¶
ShortString convert current value to string, removing ending 0s. Such as 3.00, returns 3.
func (Decimal) Sign ¶
Sign returns 1 if current value greater than 0, -1 if less than 0, 0 if equals to 0.
func (Decimal) String ¶
String implement fmt.Stringer interface, return decimal value in string format, appended 0 to scales. Such as 3.00, use ShortString() to get '3'.
func (Decimal) SubToScale ¶
SubToScale subtract the other value to specific scale.
func (Decimal) ToDecimal128 ¶
ToDecimal128 convert to IEEE 754 decimal128
func (*Decimal) UnmarshalJSON ¶
type NullDecimal ¶
type NullDecimal struct { Decimal Decimal Valid bool // Valid is true if current value is not NULL }
NullDecimal nullable decimal value
func (NullDecimal) GetBSON ¶
func (d NullDecimal) GetBSON() (interface{}, error)
GetBSON implement bson.Getter interface, marshal value to mongoDB. Marshal to string to pressure both scale and value.
func (NullDecimal) MarshalJSON ¶
func (d NullDecimal) MarshalJSON() ([]byte, error)
func (*NullDecimal) SetBSON ¶
func (d *NullDecimal) SetBSON(raw bson.Raw) error
SetBSON implement bson.Setter interface, marshal value from mongoDB
func (NullDecimal) String ¶
func (d NullDecimal) String() string
func (*NullDecimal) UnmarshalJSON ¶
func (d *NullDecimal) UnmarshalJSON(buf []byte) error