A FixedFormat is a simple object which represents a decimal (base-10) Fixed-Point data representation. Usually using this class directly is uneccessary, as passing in a Format Strings directly into the FixedNumber will automatically create this.
A format string is composed of three components, including signed-ness, bit-width and number of decimals.
A signed format string begins with fixed
, which an unsigned format string begins with ufixed
, followed by the width (in bits) and the number of decimals.
The width must be conguent to 0 mod 8 (i.e. (width % 8) == 0
) and no larger than 256 bits and the number of decimals must be no larger than 80.
For example:
- fixed128x18 is signed, 128 bits wide and has 18 decimals; this is useful for most purposes
- fixed32x0 is signed, 32 bits wide and has 0 decimals; this would be the same as a ``int32_t` in C
- ufixed32x0 is unsigned, 32 bits wide and has 0 decimals; this would be the same as a ``uint32_t` in C
- fixed is shorthand for ``fixed128x18`
- ufixed is shorthand for ``ufixed128x18`
Returns a new instance of a FixedFormat defined by value. Any valid Format Strings may be passed in as well as any object which has any of signed
, width
and decimals
defined, including a FixedFormat object.
A shorthand for fixed128x80
.
The FixedNumber constructor cannot be called directly. There are several static methods for creating a FixedNumber.
Returns an instance of a FixedNumber for value as a format.
Returns an instance of a FixedNumber for value as a format.
Returns an instance of a FixedNumber for value as a format. The value must not contain more decimals than the format permits.
Returns an instance of a FixedNumber for value with decimals as a format.
The FixedFormat of fixednumber.
Returns a new FixedNumber with the value of fixedvalue + otherValue.
Returns a new FixedNumber with the value of fixedvalue – otherValue.
Returns a new FixedNumber with the value of fixedvalue × otherValue.
Returns a new FixedNumber with the value of fixedvalue ÷ otherValue.
Returns a new FixedNumber with the value of fixedvalue rounded to decimals.
Returns a new FixedNumber with the value of fixedvalue with format.
Returns a string representation of fixednumber.
Returns a floating-point JavaScript number value of fixednumber. Due to rounding in JavaScript numbers, the value is only approximate.
Returns true if and only if value is a FixedNumber.