2019-08-22 08:52:17 +03:00
|
|
|
-----
|
|
|
|
|
|
|
|
Documentation: [html](https://docs-beta.ethers.io/)
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
2019-08-21 08:53:47 +03:00
|
|
|
FixedNumber
|
|
|
|
===========
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +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
|
|
|
|
2020-02-02 08:53:22 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Creating Instances
|
|
|
|
------------------
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
The FixedNumber constructor cannot be called directly. There are several
|
|
|
|
static methods for creating a FixedNumber.
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *FixedNumber* . **from** ( value [ , format="fixed" ] ) **=>** *[FixedNumber](./)*
|
2020-02-02 08:53:22 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns an instance of a **FixedNumber** for *value* as a *format*.
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *FixedNumber* . **fromBytes** ( aBytesLike [ , format="fixed" ] ) **=>** *[FixedNumber](./)*
|
2020-02-02 08:53:22 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns an instance of a **FixedNumber** for *value* as a *format*.
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *FixedNumber* . **fromString** ( value [ , format="fixed" ] ) **=>** *[FixedNumber](./)*
|
2020-02-02 08:53:22 +03:00
|
|
|
|
2020-02-18 01:56:50 +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-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *FixedNumber* . **fromValue** ( value [ , decimals=0 [ , format="fixed" ] ] ) **=>** *[FixedNumber](./)*
|
2020-02-02 08:53:22 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns an instance of a **FixedNumber** for *value* with *decimals* as a *format*.
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Properties
|
|
|
|
----------
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **format**
|
2020-02-02 08:53:22 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
The [FixedFormat](./) of *fixednumber*.
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Methods
|
|
|
|
-------
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
### Math Operations
|
2020-02-02 08:53:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **addUnsafe** ( otherValue ) **=>** *[FixedNumber](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a new FixedNumber with the value of *fixedvalue* **+** *otherValue*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **subUnsafe** ( otherValue ) **=>** *[FixedNumber](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a new FixedNumber with the value of *fixedvalue* **–** *otherValue*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **mulUnsafe** ( otherValue ) **=>** *[FixedNumber](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a new FixedNumber with the value of *fixedvalue* **×** *otherValue*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **divUnsafe** ( otherValue ) **=>** *[FixedNumber](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a new FixedNumber with the value of *fixedvalue* **÷** *otherValue*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **round** ( [ decimals=0 ] ) **=>** *[FixedNumber](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a new FixedNumber with the value of *fixedvalue* rounded to *decimals*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
### Conversion
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **toFormat** ( format ) **=>** *[FixedNumber](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a new FixedNumber with the value of *fixedvalue* with *format*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **toHexString** ( ) **=>** *string*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a [Hexstring](../bytes) representation of *fixednumber*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **toString** ( ) **=>** *string*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a string representation of *fixednumber*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixednumber* . **toUnsafeFloat** ( ) **=>** *float*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns a floating-point JavaScript number value of *fixednumber*.
|
|
|
|
Due to rounding in JavaScript numbers, the value is only approximate.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
### Inspection
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *FixedNumber* . **isFixedNumber** ( value ) **=>** *boolean*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
Returns true if and only if *value* is a **FixedNumber**.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
FixedFormat
|
|
|
|
-----------
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
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.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
### Format Strings
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
A format string is composed of three components, including signed-ness,
|
|
|
|
bit-width and number of decimals.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
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.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
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.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
For example:
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
* **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`
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
### Creating Instances
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *FixedFormat* . **from** ( value="fixed128x18" ) **=>** *[FixedFormat](./)*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
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.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
### Properties
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixedFormat* . **signed** **=>** *boolean*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
The signed-ness of *fixedFormat*, true if negative values are supported.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixedFormat* . **width** **=>** *number*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
The width (in bits) of *fixedFormat*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixedFormat* . **decimals** **=>** *number*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
The number of decimal points of *fixedFormat*.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### *fixedFormat* . **name** **=>** *string*
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
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.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
#### ***"fixed"***
|
2019-08-21 08:53:47 +03:00
|
|
|
|
2020-02-18 01:56:50 +03:00
|
|
|
A shorthand for `fixed128x80`.
|
2019-08-21 08:53:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-----
|
2020-02-25 22:57:11 +03:00
|
|
|
**Content Hash:** 60fa7fc0a5e28ce6608684d52fe57c2758aa6c9482cd19f71cb5b91fd7d392b8
|