Documentation ¶
Index ¶
- Constants
- func SetDigitsAfterDecimal(digits int)
- type Fixed
- func (fxd Fixed) Comma() string
- func (fxd Fixed) Div(value Fixed) Fixed
- func (fxd Fixed) Float64() float64
- func (fxd Fixed) Int64() int64
- func (fxd *Fixed) MarshalJSON() ([]byte, error)
- func (fxd *Fixed) MarshalText() ([]byte, error)
- func (fxd Fixed) MarshalYAML() (interface{}, error)
- func (fxd Fixed) Mul(value Fixed) Fixed
- func (fxd Fixed) String() string
- func (fxd Fixed) Trunc() Fixed
- func (fxd *Fixed) UnmarshalJSON(data []byte) error
- func (fxd *Fixed) UnmarshalText(text []byte) error
- func (fxd *Fixed) UnmarshalYAML(unmarshal func(interface{}) error) error
Constants ¶
const ( // Max holds the maximum fixed-point value. Max = Fixed(1<<63 - 1) // Min holds the minimum fixed-point value. Min = Fixed(-1 << 63) )
Variables ¶
This section is empty.
Functions ¶
func SetDigitsAfterDecimal ¶
func SetDigitsAfterDecimal(digits int)
SetDigitsAfterDecimal controls the number of digits after the decimal place that are tracked. WARNING: This has a global effect on all fixed-point values and should only be set once prior to use of this package. Changes to this value invalidate any fixed-point values there were created prior to the call -- there is no enforcement of this, however, so use of a pre-existing value will quietly generate bad results.
Types ¶
type Fixed ¶
type Fixed int64
Fixed holds a fixed-point value that contains up to N decimal places, where N is the value passed to SetDigitsAfterDecimal (default is 4). Values are truncated, not rounded. Values can be added and subtracted directly. For multiplication and division, the provided Mul() and Div() methods should be used.
func FromFloat64 ¶
FromFloat64 creates a new fixed-point value from a float64.
func (Fixed) Comma ¶
Comma returns the same as String(), but with commas for values of 1000 and greater.
func (Fixed) Div ¶
Div divides this value by the passed-in value, returning a new fixed-point value.
func (*Fixed) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. Note that this intentionally generates a string where necessary to ensure the correct value is retained.
func (*Fixed) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Fixed) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface. Note that this intentionally generates a string where necessary to ensure the correct value is retained.
func (Fixed) Mul ¶
Mul multiplies this value by the passed-in value, returning a new fixed-point value.
func (Fixed) Trunc ¶
Trunc returns a new value which has everything to the right of the decimal place truncated.
func (*Fixed) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Fixed) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (*Fixed) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface.