NumberFormatter

Pure Kotlin number formatting utility — no expect/actual needed.

Functions

Link copied to clipboard
fun format(value: Double, decimalPlaces: Int): String

Formats a double value with the specified number of decimal places.

fun format(value: Float, decimalPlaces: Int): String

Formats a float value with the specified number of decimal places.

Link copied to clipboard

True when char is a decimal mark reachable from a Decimal/DecimalSigned keyboard.

Link copied to clipboard

True when text could still become a number as the user types — an empty field, a lone sign, or a trailing separator. A controlled field consults this after parseDecimalOrNull returns null, so transient input like - or -. survives on the way to -1.5 instead of snapping back to the last committed value.

Link copied to clipboard

Parses a user-entered decimal whose separator follows the keyboard locale — 48,21 on a comma locale, which String.toDoubleOrNull rejects. A lone separator is always the decimal mark; grouping is only recognised when more than one appears, in which case the last one is the decimal mark. Returns null for anything unparseable.