Xnumber
Class XNumber
Extended Number class.
constructor (num: number, den: number, unit: Suffix): XNumber
Name | Type | Default | Description |
---|---|---|---|
num | number | ||
den | number | ||
unit | Suffix |
Accessor .value : number
Returns the value of this number as a decimal. For example, 2/5 and 40% would both return 0.4.
Method .clamp (min: number, max: number): XNumber
Name | Type | Default | Description |
---|---|---|---|
min | number | ||
max | number |
static Method .difference (a: XNumber, b: number|XNumber): XNumber
Calculates the difference of two numbers a and b.
Name | Type | Default | Description | |
---|---|---|---|---|
a | XNumber | |||
b | number | XNumber |
static Method .fractionFromDecimal (x: number, maxDen: number): XNumber
Converts a decimal into the closest fraction with a given maximum denominator.
Name | Type | Default | Description |
---|---|---|---|
x | number | ||
maxDen | number | 100 |
static Method .fromString (s: string): undefined|XNumber
Parses a number string, e.g. ‘1/2’ or ‘20.7%’.
Name | Type | Default | Description |
---|---|---|---|
s | string |
static Method .product (a: XNumber, b: number|XNumber): XNumber
Calculates the product of two numbers a and b.
Name | Type | Default | Description | |
---|---|---|---|---|
a | XNumber | |||
b | number | XNumber |
static Method .quotient (a: XNumber, b: number|XNumber): XNumber
Calculates the quotient of two fractions a and b.
Name | Type | Default | Description | |
---|---|---|---|---|
a | XNumber | |||
b | number | XNumber |