* Converts %%value%% into a //decimal string//, assuming %%unit%% decimal * places. The %%unit%% may be the number of decimal places or the name of * a unit (e.g. ``"gwei"`` for 9 decimal places). *
(value, unit)
| 41 | * |
| 42 | */ |
| 43 | function formatUnits(value, unit) { |
| 44 | let decimals = 18; |
| 45 | if (typeof (unit) === "string") { |
| 46 | const index = names.indexOf(unit); |
| 47 | (0, errors_js_1.assertArgument)(index >= 0, "invalid unit", "unit", unit); |
| 48 | decimals = 3 * index; |
| 49 | } |
| 50 | else if (unit != null) { |
| 51 | decimals = (0, maths_js_1.getNumber)(unit, "unit"); |
| 52 | } |
| 53 | return fixednumber_js_1.FixedNumber.fromValue(value, decimals, { decimals, width: 512 }).toString(); |
| 54 | } |
| 55 | exports.formatUnits = formatUnits; |
| 56 | /** |
| 57 | * Converts the //decimal string// %%value%% to a BigInt, assuming |
no test coverage detected