min()

marjoriekohn11 total contributions
Published Oct 27, 2023
Contribute to Docs
The min()
function in Kotlin’s math
class is used to determine the smaller value between two numbers of the same Number
type.
Syntax
min(a, b)
a
: The number of typeNumber
to be compared.b
: Another number, of the same type asa
.
The min()
function returns the smaller value between a
and b
. If either value is NaN
, the function returns NaN
.
Note: To compare more than two numbers, use
minOf()
.
Example
This example demonstrates how to use the min()
function to determine the smaller value of two numbers:
import kotlin.math.minfun main() {val minValue = min(3.4, 3.5)println(minValue)}
The min()
function compares 3.4
and 3.5
and returns the smaller number.
The output of this code will be:
3.4
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.