2019-08-21 08:53:47 +03:00
|
|
|
_section: FixedNumber @<fixednumber>
|
|
|
|
|
2020-02-18 01:56:13 +03:00
|
|
|
A **FixedNumber** is a fixed-width (in bits) number with an internal
|
|
|
|
base-10 divisor, which allows it to represent a decimal fractional
|
|
|
|
component.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
_subsection: Creating Instances
|
|
|
|
|
|
|
|
The FixedNumber constructor cannot be called directly. There are several
|
|
|
|
static methods for creating a FixedNumber.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: FixedNumber.from(value [ , format = "fixed" ] ) => [[fixednumber]] @SRC<bignumber:FixedNumber.from>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns an instance of a **FixedNumber** for //value// as a //format//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: FixedNumber.fromBytes(aBytesLike [ , format = "fixed" ] ) => [[fixednumber]] @SRC<bignumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns an instance of a **FixedNumber** for //value// as a //format//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: FixedNumber.fromString(value [ , format = "fixed" ] ) => [[fixednumber]] @SRC<bignumber:FixedNumber.fromString>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns an instance of a **FixedNumber** for //value// as a //format//. The //value// must
|
|
|
|
not contain more decimals than the //format// permits.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: FixedNumber.fromValue(value [ , decimals = 0 [ , format = "fixed" ] ] ) => [[fixednumber]] @SRC<bignumber:FixedNumber.fromValue>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns an instance of a **FixedNumber** for //value// with //decimals// as a //format//.
|
|
|
|
|
|
|
|
|
|
|
|
_subsection: Properties
|
|
|
|
|
|
|
|
_property: fixednumber.format
|
|
|
|
The [FixedFormat](fixedformat) of //fixednumber//.
|
|
|
|
|
|
|
|
|
|
|
|
_subsection: Methods
|
|
|
|
|
|
|
|
_heading: Math Operations
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.addUnsafe(otherValue) => [[fixednumber]] @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a new FixedNumber with the value of //fixedvalue// **+** //otherValue//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.subUnsafe(otherValue) => [[fixednumber]] @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a new FixedNumber with the value of //fixedvalue// **–** //otherValue//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.mulUnsafe(otherValue) => [[fixednumber]] @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a new FixedNumber with the value of //fixedvalue// **×** //otherValue//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.divUnsafe(otherValue) => [[fixednumber]] @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a new FixedNumber with the value of //fixedvalue// **÷** //otherValue//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.round([ decimals = 0 ]) => [[fixednumber]] @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a new FixedNumber with the value of //fixedvalue// rounded to //decimals//.
|
|
|
|
|
|
|
|
|
|
|
|
_heading: Conversion
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.toFormat(format) => [[fixednumber]] @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a new FixedNumber with the value of //fixedvalue// with //format//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.toHexString() => string @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a [Hexstring](hexstring) representation of //fixednumber//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.toString() => string @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a string representation of //fixednumber//.
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: fixednumber.toUnsafeFloat() => float @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns a floating-point JavaScript number value of //fixednumber//.
|
|
|
|
Due to rounding in JavaScript numbers, the value is only approximate.
|
|
|
|
|
|
|
|
|
|
|
|
_heading: Inspection
|
|
|
|
|
2020-01-10 09:01:00 +03:00
|
|
|
_property: FixedNumber.isFixedNumber(value) => boolean @SRC<bignumber/fixednumber>
|
2019-08-21 08:53:47 +03:00
|
|
|
Returns true if and only if //value// is a **FixedNumber**.
|
|
|
|
|
2020-02-18 01:56:13 +03:00
|
|
|
|
|
|
|
_subsection: FixedFormat @<fixedformat>
|
|
|
|
|
|
|
|
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 [[fixedformatstring]]
|
|
|
|
directly into the [[fixednumber]] will automatically create this.
|
|
|
|
|
|
|
|
_heading: Format Strings @<fixedformatstring>
|
|
|
|
|
|
|
|
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
|
2020-04-17 05:25:05 +03:00
|
|
|
- **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``
|
2020-02-18 01:56:13 +03:00
|
|
|
|
|
|
|
_heading: Creating Instances
|
|
|
|
|
|
|
|
_property: FixedFormat.from(value = "fixed128x18") => [[fixedformat]] @<fixednumber-from> @SRC<bignumber/fixednumber:FixedFormat.from>
|
|
|
|
|
|
|
|
Returns a new instance of a **FixedFormat** defined by //value//. Any valid [[fixedformatstring]]
|
|
|
|
may be passed in as well as any object which has any of ``signed``, ``width`` and ``decimals``
|
|
|
|
defined, including a [[fixedformat]] object.
|
|
|
|
|
|
|
|
_heading: Properties
|
|
|
|
|
|
|
|
_property: fixedFormat.signed => boolean
|
|
|
|
The signed-ness of //fixedFormat//, true if negative values are supported.
|
|
|
|
|
|
|
|
_property: fixedFormat.width => number
|
|
|
|
The width (in bits) of //fixedFormat//.
|
|
|
|
|
|
|
|
_property: fixedFormat.decimals => number
|
|
|
|
The number of decimal points of //fixedFormat//.
|
|
|
|
|
|
|
|
_property: fixedFormat.name => string
|
|
|
|
The name of the //fixedFormat//, which can be used to recreate the format
|
|
|
|
and is the string that the Solidity language uses to represent this format.
|
|
|
|
|
|
|
|
_definition: **//"fixed"//**
|
|
|
|
A shorthand for ``fixed128x80``.
|
|
|
|
|