formatMoney

fun Long.formatMoney(symbol: String = "", minorDigits: Int = 2, fractionDigits: Int = minorDigits, grouping: Grouping = Grouping.Western, dropZeroFraction: Boolean = false): String(source)

Display formatter for money held as minor units (paise, cents): grouping, symbol and a fixed fraction, e.g. 24990000L.formatMoney("₹", grouping = Grouping.Indian) ->₹2,49,900.00.

  • minorDigits is the currency exponent of the receiver (2 for INR/USD, 0 for JPY, 3 for KWD).

  • fractionDigits is how many to show, clamped to 0..minorDigits. Showing fewer than minorDigits rounds half-up (away from zero on the magnitude: 0.5 -> 1, -0.5 -> -1), never truncates. Display only: keep ledger values exact in minor units. The wire-format formatter stays minorToDecimalString.

  • The sign goes before the symbol (-₹10.50); a value that rounds to zero shows no sign.

  • dropZeroFraction hides an all-zero fraction (₹100 instead of ₹100.00).

  • Long.MIN_VALUE is handled (the magnitude is computed unsigned).