MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / formatUnits

Function formatUnits

lib.commonjs/utils/units.js:43–54  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

41 *
42 */
43function 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}
55exports.formatUnits = formatUnits;
56/**
57 * Converts the //decimal string// %%value%% to a BigInt, assuming

Callers 1

formatEtherFunction · 0.70

Calls 2

toStringMethod · 0.45
fromValueMethod · 0.45

Tested by

no test coverage detected