The `abs` method returns the absolute value of a double.
The syntax of double.abs() method is:
double abs()
This abs() method of double returns the absolute value of this double
.
double.abs() returns value of type double
.
In this example,
num
with a value of -3.14
.abs()
method on num
to find its absolute value.void main() {
double num = -3.14;
double absValue = num.abs();
print('Absolute value of -3.14: $absValue');
}
Absolute value of -3.14: 3.14
In this example,
num
with a value of 5.0
.abs()
method on num
to find its absolute value.void main() {
double num = 5.0;
double absValue = num.abs();
print('Absolute value of 5.0: $absValue');
}
Absolute value of 5.0: 5.0
In this example,
num
with a value of -7.5
.abs()
method on num
to find its absolute value.void main() {
double num = -7.5;
double absValue = num.abs();
print('Absolute value of -7.5: $absValue');
}
Absolute value of -7.5: 7.5
In this Dart tutorial, we learned about abs() method of double: the syntax and few working examples with output and detailed explanation for each example.