formatDecimals

Formats this value with exactly decimals fractional digits, locale-independent.

Rounding mode is half-up with ties rounded away from zero, and carries propagate across the decimal point: 9.99.formatDecimals(1) is "10.0". The decimal separator is always '.' and no grouping is applied. With decimals of zero the result has no decimal point. Values that round to zero are printed without a sign. NaN and infinities format as "NaN", "Infinity", and "-Infinity".

Throws IllegalArgumentException when decimals is outside 0..15, or when the magnitude scaled by 10^decimals exceeds Long.MAX_VALUE.


fun Float.formatDecimals(decimals: Int): String

Formats this value with exactly decimals fractional digits, locale-independent.

Converts to Double and delegates to Double.formatDecimals, so rounding is half-up with ties away from zero and carries propagate: 9.99f.formatDecimals(1) is "10.0". Throws IllegalArgumentException when decimals is outside 0..15.