The `round` method in Dart returns the integer itself because integers are already whole numbers and cannot be rounded to another integer.
The syntax of int.round() method is:
int round()
This round() method of int returns this.
int.round() returns value of type int
.
In this example,
num
with the value 4.round()
method on num
returns the integer itself.void main() {
int num = 4;
int roundNum = num.round();
print('Round of $num: $roundNum');
}
Round of 4: 4
In this example,
negativeNum
with the value -3.round()
method on negativeNum
returns the integer itself.void main() {
int negativeNum = -3;
int roundNegative = negativeNum.round();
print('Round of $negativeNum: $roundNegative');
}
Round of -3: -3
In this example,
integerNum
with the value 7.round()
method on integerNum
returns the integer itself.void main() {
int integerNum = 7;
int roundInteger = integerNum.round();
print('Round of $integerNum: $roundInteger');
}
Round of 7: 7
In this Dart tutorial, we learned about round() method of int: the syntax and few working examples with output and detailed explanation for each example.