To round a double value to an int value in Dart, the method round()
is used.
The round()
method returns the value of a number rounded to the nearest integer.
num.round()
The method round()
takes no parameter.
This method returns the value of a number rounded to the nearest integer.
The following code shows how to use the method round()
in Dart:
void main() {//converting to nearest int valueint num = (-2.3).round();print('The temperature is ${num} in Texas');int num2 = (-2.5).round();print(num2);double n1 = 12.023;double n2 = 12.89;// compares if values are equalif (n1.round() == n2.round()){print('There are 12 apples in the basket');}else {print('Not equal');}// display resultvar value = n1.round();print( value );value = n2.round();print( value );}