Files
dickloads/src/lib/format.ts

17 lines
590 B
TypeScript

import type { Big } from 'big.js';
import { FRACTIONAL_DIGITS, INTEGER_DIGITS } from './config';
/**
* Format a Big value for display.
* Uses FRACTIONAL_DIGITS decimal places (fixed-point).
* If INTEGER_DIGITS is set, zero-pads the integer portion to that width.
*/
export function formatBig(v: Big): string {
const fixed = v.toFixed(FRACTIONAL_DIGITS);
if (INTEGER_DIGITS === undefined) return fixed;
const [intPart, fracPart] = fixed.split('.');
const paddedInt = intPart.padStart(INTEGER_DIGITS, '0');
return fracPart !== undefined ? `${paddedInt}.${fracPart}` : paddedInt;
}