Phase 2: core converter, live conversion, URL state, highlight interaction

This commit is contained in:
Falkan
2026-03-16 21:34:16 -04:00
parent 65f8bc1b9f
commit 8f835c35d2
9 changed files with 430 additions and 1 deletions

16
src/lib/format.ts Normal file
View File

@@ -0,0 +1,16 @@
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;
}