Documentation
¶
Index ¶
- Variables
- func SetPrecisionBits(bits uint64)
- func SetStringDecimalPlaces(dp uint64)
- 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) 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) UnmarshalJSON(bytes []byte) error
- func (n Numeric) Value() (driver.Value, error)
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 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) 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) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.