min()
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
Contribute to Docs
- 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.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours