coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T(source)
val value = 15
val maximum = 10

val result = value.coerceAtMost(maximum)  // result = 10
println(result)                           // prints: 10

Source