MCPcopy Create free account
hub / github.com/dfinity/orbit / formatBalance

Function formatBalance

apps/wallet/src/utils/helper.utils.ts:91–98  ·  view source on GitHub ↗
(amount: bigint, decimals: number)

Source from the content-addressed store, hash-verified

89
90// Formats a balance that is a bigint into a string with the correct number of decimals
91export const formatBalance = (amount: bigint, decimals: number): string => {
92 const integerPart = amount / BigInt(10 ** decimals);
93 const remainder = amount % BigInt(10 ** decimals);
94 const integerPartStr = integerPart.toString();
95 const remainderStr = remainder.toString().padStart(decimals, '0');
96
97 return `${integerPartStr}.${remainderStr}`;
98};
99
100export const amountToBigInt = (amount: string, decimals: number): bigint => {
101 const [integer, decimal] = amount.split('.');

Callers 1

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected