The `roundToDouble` method in Dart returns the integer double value closest to the given number.
The syntax of double.roundToDouble() method is:
double roundToDouble()
This roundToDouble() method of double returns the integer double value closest to this
.
double.roundToDouble() returns value of type double
.
In this example,
num
with the value 4.2.roundToDouble()
method to round num
to the nearest integer as a double value.void main() {
double num = 4.2;
double rounded = num.roundToDouble();
print('Rounded value of $num: $rounded');
}
Rounded value of 4.2: 4
In this example,
num
with the value 4.8.roundToDouble()
method to round num
to the nearest integer as a double value.void main() {
double num = 4.8;
double rounded = num.roundToDouble();
print('Rounded value of $num: $rounded');
}
Rounded value of 4.8: 5
In this example,
num
with the value -4.5.roundToDouble()
method to round num
to the nearest integer as a double value.void main() {
double num = -4.5;
double rounded = num.roundToDouble();
print('Rounded value of $num: $rounded');
}
Rounded value of -4.5: -5
In this Dart tutorial, we learned about roundToDouble() method of double: the syntax and few working examples with output and detailed explanation for each example.