BalanceFormatter
Utility for formatting token amounts for display.
Responsibilities:
Convert raw amounts (BigInteger) to human-readable strings
Add thousands separators (1,234,567)
Handle decimal places (based on token precision)
Append token symbols (e.g., "1,234.56 DUST")
Token Precision:
DUST: 15 decimals (1 DUST = 10^15 Specks)
NIGHT/TNIGHT: 6 decimals (1 NIGHT = 1,000,000 Stars)
Custom tokens: Configurable precision (default 6)
Performance: DecimalFormat is cached to avoid recreating on every format call.
Example Usage:
@Inject lateinit var formatter: BalanceFormatter
formatter.format(BigInteger("1234567890"), "DUST") // "1,234.567890 DUST"
formatter.format(BigInteger.ZERO, "TNIGHT") // "0.000000 TNIGHT"Content copied to clipboard