Package-level declarations

Functions

Link copied to clipboard
fun Double.clamp(min: Double, max: Double): Double

Clamps a Double between min and max. Example: 150.0.clamp(0.0, 100.0) → 100.0

Link copied to clipboard

Returns true if the number is even.

Link copied to clipboard

Returns true if the number is odd.

Link copied to clipboard
fun Double.mapRange(fromMin: Double, fromMax: Double, toMin: Double, toMax: Double): Double

Linearly interpolates a Double in [fromMin, fromMax] to [toMin, toMax]. Example: 50.0.mapRange(0.0, 100.0, 0.0, 1.0) → 0.5

Link copied to clipboard

Computes the percentage change from previous to this value. Returns null if previous is zero. Example: 120.0.percentageChange(100.0) → 20.0

Link copied to clipboard

Computes the percentage of ` `part` ` out of ` `total` `, returning 0.0 if ` `total` ` is zero. Example: 25.0.percentOf(200.0) → 12.5

Link copied to clipboard
fun Double.round(decimals: Int = 2): String

Formats a Double with decimals decimal places. Example: 3.14159.round(2) → "3.14"

Link copied to clipboard
fun Double.safeDivide(divisor: Double, fallback: Double = 0.0): Double

Safely divides by divisor, returning fallback when divisor is zero. Example: 10.0.safeDivide(0.0) → 0.0

Link copied to clipboard

Returns the sign of the number as "+", "-", or "". Example: 42.sign() → "+"

Link copied to clipboard
fun Double.toChangeLabel(previous: Double, decimals: Int = 1): String

Formats the percentage change from previous to this value as a signed string. Returns "N/A" if previous is zero. Example: 120.0.toChangeLabel(100.0) → "+20.0%"

Link copied to clipboard
fun Double.toCompact(decimals: Int = 1): String

Abbreviates large numbers with K/M/B/T suffixes. Example: 1_500_000.0.toCompact() → "1.5M"

fun Long.toCompact(decimals: Int = 1): String
Link copied to clipboard
fun Int.toCompactString(decimals: Int = 1): String
fun Long.toCompactString(decimals: Int = 1): String
Link copied to clipboard
fun Double.toPercent(decimals: Int = 1): String

Formats a Double in the range 0.0, 1.0 as a percentage string. Example: 0.753.toPercent() → "75.3%"

Link copied to clipboard
fun Double.toPercentLabel(decimals: Int = 1): String

Formats a Double already in percentage scale (0–100) as a percentage string. Example: 75.3.toPercentLabel() → "75.3%"

Link copied to clipboard
fun Double.toSignedPercent(decimals: Int = 1): String

Formats a percentage with an explicit sign (useful for change indicators). Example: (-0.05).toSignedPercent() → "-5.0%" Example: 0.12.toSignedPercent() → "+12.0%"

Link copied to clipboard

Formats a number with thousands separators. Example: 1234567.toThousands() → "1,234,567"

fun Double.toThousands(decimals: Int = 2): String

Formats a Double with thousands separators and fixed decimal places. Example: 1234567.89.toThousands(2) → "1,234,567.89"

Link copied to clipboard
fun Double.withSign(decimals: Int = 0): String

Formats a number with an explicit sign prefix. Example: 42.0.withSign() → "+42.0"

Link copied to clipboard
fun Int.zeroPad(width: Int): String

Pads an integer with leading zeros to the given width. Example: 7.zeroPad(3) → "007"