thomas.s
thomas.s

Reputation: 348

how to convert negative int to positive int in flutter

for example if i have a list like

List list = [-12,3,-24,58,12];

i have already tried this ,i did not understand it https://stackoverflow.com/questions/55374813/why-abs-function-in-dart-return-negative-number-when-not-wrapped-in-parenthesi\ i want to convert all parameters to a positive parameters
or if i had only a integer which is negative how to convert it to a positive integer
if you need more information please let me know and thanks for the helps

Upvotes: 9

Views: 20475

Answers (1)

Saeed Fekri
Saeed Fekri

Reputation: 1135

You can use Abs method for numbers to get absolute value:

int number = -5;
print(number.abs()); // prints: 5

https://dart.dev/guides/language/language-tour#numbers

Upvotes: 38

Related Questions