coerceAtMost

fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T(source)

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

Since Kotlin

1.0

Return

this value if it's less than or equal to the maximumValue or the maximumValue otherwise.

Samples


fun Byte.coerceAtMost(maximumValue: Byte): Byte(source)
fun Short.coerceAtMost(maximumValue: Short): Short(source)
fun Int.coerceAtMost(maximumValue: Int): Int(source)
fun Long.coerceAtMost(maximumValue: Long): Long(source)
fun Float.coerceAtMost(maximumValue: Float): Float(source)
fun Double.coerceAtMost(maximumValue: Double): Double(source)

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

Since Kotlin

1.0

Return

this value if it's less than or equal to the maximumValue or the maximumValue otherwise.

Samples


fun UInt.coerceAtMost(maximumValue: UInt): UInt(source)
fun ULong.coerceAtMost(maximumValue: ULong): ULong(source)
fun UByte.coerceAtMost(maximumValue: UByte): UByte(source)
fun UShort.coerceAtMost(maximumValue: UShort): UShort(source)

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

Since Kotlin

1.5

Return

this value if it's less than or equal to the maximumValue or the maximumValue otherwise.

Samples