Documentation ¶
Overview ¶
package fixed implements a fixed-point number, where both mantissa and exponent are stored in a single number. Can be used to represent currency rates with up to 16 digits of precision.
Index ¶
- Constants
- Variables
- type Value
- func (v Value) Float64() float64
- func (v Value) GoString() string
- func (v Value) MantUint64() uint64
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) Normalized() Value
- func (v Value) String() string
- func (v Value) ToExp(exp int) Value
- func (v Value) Uint64() uint64
- func (v *Value) UnmarshalJSON(data []byte) error
Constants ¶
View Source
const ( // JSONModeString produces values as strings, like `"1234.5678"` JSONModeString = iota // JSONModeFloat marshals values as floats, like `1234.5678`. JSONModeFloat // JSONModeME marshals values with mantissa and exponent, like `{"m":123,"e":-5}`. JSONModeME // JSONModeCompact will choose the shortest form between JSONModeString and JSONModeME. JSONModeCompact )
Variables ¶
View Source
var ( // JSONMode defines the way all values are marshaled into json, see JSONMode* constants. // This variable is not thread-safe, so this should be changed on program start. JSONMode = JSONModeCompact )
Functions ¶
This section is empty.
Types ¶
type Value ¶
type Value number
Value is a positive fixed-point number. 8 high bits are used for exponent, the others are for mantissa.
func FromFloat64 ¶
FromFloat64 returns a value for given float64.
func FromMantAndExp ¶
FromMantAndExp returns a value for given mantissa and exponent.
func FromUint64 ¶
FromUint64 returns a value for given uint64 number.
func (Value) MarshalJSON ¶
MarshalJSON marshals value according to current JSONMode.
func (Value) Normalized ¶
Normalized eliminates trailing zeros in the fractional part.
func (*Value) UnmarshalJSON ¶
UnmarshalJSON unmarshals a string, float, and an object into a value.
Click to show internal directories.
Click to hide internal directories.