The `round` method returns the integer closest to the given double.
The syntax of double.round() method is:
int round()
This round() method of double returns the integer closest to this
.
double.round() returns value of type int
.
In this example,
num
with a value of 3.6
.round()
method on num
to round it to the nearest integer.void main() {
double num = 3.6;
int roundedValue = num.round();
print('Rounded value of 3.6: $roundedValue');
}
Rounded value of 3.6: 4
In this example,
num
with a value of -4.3
.round()
method on num
to round it to the nearest integer.void main() {
double num = -4.3;
int roundedValue = num.round();
print('Rounded value of -4.3: $roundedValue');
}
Rounded value of -4.3: -4
In this example,
num
with a value of 7.8
.round()
method on num
to round it to the nearest integer.void main() {
double num = 7.8;
int roundedValue = num.round();
print('Rounded value of 7.8: $roundedValue');
}
Rounded value of 7.8: 8
In this Dart tutorial, we learned about round() method of double: the syntax and few working examples with output and detailed explanation for each example.