Phase 2: core converter, live conversion, URL state, highlight interaction
This commit is contained in:
16
src/lib/format.ts
Normal file
16
src/lib/format.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user