The `abs()` method returns the absolute value of this integer.
The syntax of BigInt.abs() method is:
BigInt abs()
This abs() method of BigInt returns the absolute value of this integer.
BigInt.abs() returns value of type BigInt
.
In this example,
number
with a value of -5
.abs()
method to calculate its absolute value.void main() {
int number = -5;
BigInt absValue = BigInt.from(number).abs();
print('Absolute value of -5: $absValue');
}
Absolute value of -5: 5
In this example,
number
with a value of -7.5
.abs()
method to calculate its absolute value as BigInt.void main() {
double number = -7.5;
BigInt absValue = BigInt.from(number.toInt()).abs();
print('Absolute value of -7.5: $absValue');
}
Absolute value of -7.5: 7
In this example,
bigInt
with a large negative value.abs()
method to calculate its absolute value.void main() {
BigInt bigInt = BigInt.parse('-12345678901234567890');
BigInt absValue = bigInt.abs();
print('Absolute value of BigInt: $absValue');
}
Absolute value of BigInt: 12345678901234567890
In this Dart tutorial, we learned about abs() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.