Function formatUnits
Parameters
- value: string | number | bigint
The value in smallest units (e.g., 1000000 = 1 KLV)
- decimals: number = 6
The number of decimals (default: 6 for KLV/KFI)
Returns string
Formatted string representation
Example
formatUnits(1000000n) // '1'
formatUnits(1500000n) // '1.5'
formatUnits(1234567n) // '1.234567'
formatUnits(500n) // '0.0005'
formatUnits('2000000', 6) // '2'
formatUnits(1000, 3) // '1' (with 3 decimals)See
- parseUnits for the reverse operation
- formatKLV for KLV-specific formatting
- value: string | number | bigint
Format a value from its smallest unit to a human-readable string
Converts amounts from blockchain smallest units to decimal representation. Trailing zeros are automatically removed from the fractional part.