The min()
function returns the smallest value among two numbers sent as parameters. The image below shows a visual representation of the min()
function.
To use the min()
function, you will need to import the dart:math
library as shown below:
import dart:math
The syntax of the min
function is as follows:
type min(type num-1, type num-2)
// Type extends number
The min()
function takes two numbers as parameters.
The numbers can be
Int
,Double
,Float
, orLong
.
The min()
function returns the smallest value from the two numbers sent as parameters.
The code below shows how to use min()
in Dart.
import 'dart:convert';import 'dart:math';void main() {// two positive numbersprint("The value of min(10, 0) = ${min(10, 0)}");//one positive and the other negativeprint("The value of min(4, -6) = ${min(4, -6)}");// both negative numbersprint("The value of min(-10, -9) = ${min(-10, -9)}");// both double numbersprint("The value of min(12.234,1.2345) = ${min(12.234,1.2345)}");// one int and the other doubleprint("The value of min(12.234,1) = ${min(12.234,1)}");}
For every pair of values in the code above, the min()
function returns the smaller of the two.