formatCkBtc.ts
1 export function formatCkBtc(amount: bigint | number | null | undefined) { 2 if (amount === undefined) return "0"; 3 amount = typeof amount === "number" ? BigInt(amount) : amount; 4 if (!amount) return "0"; 5 const integerPart = amount / 100000000n; 6 const fractionalPart = amount % 100000000n; 7 const fractionalPartString = fractionalPart.toString().padStart(8, "0"); 8 const fractionalPartTrimmed = fractionalPartString.replace(/0+$/, ""); // Removes trailing zeroes 9 return `${integerPart.toLocaleString()}.${fractionalPartTrimmed}`; 10 }