The `abs` method in Dart returns the absolute value of this integer.
The syntax of int.abs() method is:
int abs()
This abs() method of int returns the absolute value of this integer.
int.abs() returns value of type int
.
In this example,
-5
to the integer variable num1
.num1
using the abs()
method.void main() {
int num1 = -5;
int absNum1 = num1.abs();
print('Absolute value of $num1: $absNum1');
}
Absolute value of -5: 5
In this example,
10
to the integer variable num2
.num2
using the abs()
method.void main() {
int num2 = 10;
int absNum2 = num2.abs();
print('Absolute value of $num2: $absNum2');
}
Absolute value of 10: 10
In this example,
0
to the integer variable num3
.num3
using the abs()
method.void main() {
int num3 = 0;
int absNum3 = num3.abs();
print('Absolute value of $num3: $absNum3');
}
Absolute value of 0: 0
In this Dart tutorial, we learned about abs() method of int: the syntax and few working examples with output and detailed explanation for each example.