* Creates a new [[FixedNumber]] for %%value%% divided by * %%decimal%% places with %%format%%. * * This will throw a [[NumericFaultError]] if %%value%% (once adjusted * for %%decimals%%) cannot fit in %%format%%, either due to overflow * or underflow (precision loss).
(_value, _decimals, _format)
| 463 | * or underflow (precision loss). |
| 464 | */ |
| 465 | static fromValue(_value, _decimals, _format) { |
| 466 | const decimals = (_decimals == null) ? 0 : (0, maths_js_1.getNumber)(_decimals); |
| 467 | const format = getFormat(_format); |
| 468 | let value = (0, maths_js_1.getBigInt)(_value, "value"); |
| 469 | const delta = decimals - format.decimals; |
| 470 | if (delta > 0) { |
| 471 | const tens = getTens(delta); |
| 472 | (0, errors_js_1.assert)((value % tens) === BN_0, "value loses precision for format", "NUMERIC_FAULT", { |
| 473 | operation: "fromValue", fault: "underflow", value: _value |
| 474 | }); |
| 475 | value /= tens; |
| 476 | } |
| 477 | else if (delta < 0) { |
| 478 | value *= getTens(-delta); |
| 479 | } |
| 480 | checkValue(value, format, "fromValue"); |
| 481 | return new FixedNumber(_guard, value, format); |
| 482 | } |
| 483 | /** |
| 484 | * Creates a new [[FixedNumber]] for %%value%% with %%format%%. |
| 485 | * |
no test coverage detected