Documentation
¶
Index ¶
- Variables
- func SetPrecisionBits(bits uint64)
- func SetStringDecimalPlaces(dp uint64)
- type NullNumeric
- func (n NullNumeric) MarshalBinary() ([]byte, error)
- func (n NullNumeric) MarshalJSON() ([]byte, error)
- func (n *NullNumeric) Scan(value any) error
- func (n *NullNumeric) UnmarshalBinary(data []byte) error
- func (n *NullNumeric) UnmarshalJSON(bytes []byte) error
- func (n NullNumeric) Value() (driver.Value, error)
- type Numeric
- func (n Numeric) Abs() Numeric
- func (n Numeric) Add(x any) Numeric
- func (n Numeric) Ceil(dp int) Numeric
- func (n Numeric) Destroy()
- func (n Numeric) Divide(x any) Numeric
- func (n Numeric) Equal(x any) bool
- func (n Numeric) Float32() float32
- func (n Numeric) Float64() float64
- func (n Numeric) Floor(dp int) Numeric
- func (n Numeric) GreaterThan(x any) bool
- func (n Numeric) GreaterThanOrEqual(x any) bool
- func (n Numeric) Int() int
- func (n Numeric) Int16() int16
- func (n Numeric) Int32() int32
- func (n Numeric) Int64() int64
- func (n Numeric) Int8() int8
- func (n Numeric) LessThan(x any) bool
- func (n Numeric) LessThanOrEqual(x any) bool
- func (n Numeric) MarshalBinary() ([]byte, error)
- func (n Numeric) MarshalJSON() ([]byte, error)
- func (n Numeric) Multiply(x any) Numeric
- func (n Numeric) Neg() Numeric
- func (n Numeric) Pow(power any) Numeric
- func (n *Numeric) Scan(value any) error
- func (n Numeric) String() string
- func (n Numeric) StringDecimalPlaces(dp uint64) string
- func (n Numeric) Subtract(x any) Numeric
- func (n Numeric) Truncate(dp int) Numeric
- func (n Numeric) Uint() uint
- func (n Numeric) Uint16() uint16
- func (n Numeric) Uint32() uint32
- func (n Numeric) Uint64() uint64
- func (n Numeric) Uint8() uint8
- func (n *Numeric) UnmarshalBinary(data []byte) error
- func (n *Numeric) UnmarshalJSON(bytes []byte) error
- func (n Numeric) Value() (driver.Value, error)
- type NumericArray
Constants ¶
This section is empty.
Variables ¶
var ( PrecisionBits uint64 = 53 // Default MPFR precision StringDecimalPlaces uint64 = 10 // Default decimal places for string conversion )
region Global Variables
Functions ¶
func SetPrecisionBits ¶
func SetPrecisionBits(bits uint64)
Sets the default precision bits when doing arithmetic operations. The upper limit is "virtually" unlimited. However, more precision bits will make your app use more RAM. Cranking this number up to a large number will also make arithmetic operations slower. So bear this in mind. Default value is 53.
func SetStringDecimalPlaces ¶
func SetStringDecimalPlaces(dp uint64)
Sets the decimal places shown when .String() is called. The upper limit is "virtually" unlimited. However, more decimal places will make your number inaccurate. Example: 1.23 will be represented as 1.22999999... if you set a high decimal places, with not enough precision bits. You can overcome this by setting a higher precision bits, but bear in mind the consequences. Default value is 10.
Types ¶
type NullNumeric ¶ added in v0.1.0
func NewNull ¶ added in v0.1.0
func NewNull(x any) NullNumeric
Creates a new null numeric value. The type of x has to be int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64 or string.
func NewNullWithError ¶ added in v0.1.0
func NewNullWithError(x any) (NullNumeric, error)
Creates a new null numeric value, with error handling. The type of x has to be int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64 or string.
func (NullNumeric) MarshalBinary ¶ added in v0.1.1
func (n NullNumeric) MarshalBinary() ([]byte, error)
Implements go-redis encoding interface.
func (NullNumeric) MarshalJSON ¶ added in v0.1.0
func (n NullNumeric) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*NullNumeric) Scan ¶ added in v0.1.0
func (n *NullNumeric) Scan(value any) error
Scan implements the sql.Scanner interface.
func (*NullNumeric) UnmarshalBinary ¶ added in v0.1.1
func (n *NullNumeric) UnmarshalBinary(data []byte) error
Implements go-redis decoding interface.
func (*NullNumeric) UnmarshalJSON ¶ added in v0.1.0
func (n *NullNumeric) UnmarshalJSON(bytes []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type Numeric ¶
type Numeric struct {
// contains filtered or unexported fields
}
func New ¶
Creates a new numeric value. The type of x has to be int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64 or string.
func NewWithError ¶
Creates a new numeric value, with error handling. The type of x has to be int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64 or string.
func (Numeric) Divide ¶
Divide a number and return the result. This will not modify the original number.
func (Numeric) GreaterThan ¶
GreaterThan returns true if the number is greater than `x`.
func (Numeric) GreaterThanOrEqual ¶
GreaterThanOrEqual returns true if the number is greater than or equal to `x`.
func (Numeric) LessThanOrEqual ¶
LessThanOrEqual returns true if the number is less than or equal to `x`.
func (Numeric) MarshalBinary ¶ added in v0.1.1
Implements go-redis encoding interface.
func (Numeric) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Numeric) Multiply ¶
Multiply a number and return the result. This will not modify the original number.
func (Numeric) Pow ¶
Exponent the current number to the power of `x` and return the result. This will not modify the original number.
func (Numeric) String ¶
Returns numeric as a string. The default number of decimal places is 10. You can modify the default number of decimal places by using SetStringDecimalPlaces function.
func (Numeric) StringDecimalPlaces ¶
Returns numeric as a string with a specified number of decimal places.
func (Numeric) Subtract ¶
Subtract a number and return the result. This will not modify the original number.
func (*Numeric) UnmarshalBinary ¶ added in v0.1.1
Implements go-redis decoding interface.
func (*Numeric) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type NumericArray ¶ added in v0.1.0
type NumericArray []Numeric
Array form of Numeric, used for scanning and storing arrays of Numeric in postgresql.
func (*NumericArray) Scan ¶ added in v0.1.0
func (a *NumericArray) Scan(src interface{}) error
Scan implements the sql.Scanner interface.