Num
is the main way of interacting with DecimalSystem. It wraps around a number (or numeric string) and provides features to convert to different bases. For example, to convert a number to base 16, you can do:
new Num(82).toBase(16).toString();
new Num(options)
Create a new Num
instance to do base conversions.
Name | Description | Type | Example |
---|---|---|---|
options | The options for the num. This includes the number being wrapped, as well as information about it (such as its base). | String/Number or NumOptions | 26 |
num.toBase(base)
Convert a Num
to another base. Note that base conversions are only done in toString
; this method simply sets the base that the Num
will be converted to.
Name | Description | Type | Example |
---|---|---|---|
base | The base that the Num will be converted to. | Number (greater than 1) | 16 |
num.toString(precision?)
Turn a Num
into a string. This may or may not be a valid Number, depending on the base used.
Name | Description | Type | Example |
---|---|---|---|
precision? | The maximum amount of decimal digits that will appear in the number. For example, if the default (8) is used, a number will always have 8 or fewer decimals. | Number | 8 |