Take only values after the comma in a double

Asked

Viewed 41 times

0

What is the best way in Dart to pick up the value after the comma/point in a double?

Ex: double x = 21.16;

How do I get only 16?

How do I get only 21?

I’m using the x.truncate();.

1 answer

1


The truncate() is a way to take the whole part , the round() is another, but for this case the best would be toInt().

Always use the documentation to learn more about the API available for the language.

To get the decimal part is pure mathematics, it is not programming (in fact the bulk of what is learned in programming is mathematics, something that is something new within it, but it is always mathematics, it is this pure mathematical case), subtract the total value with the whole part, the result will obviously be the decimal part.

Just remembering that double does not serve for monetary value. See the decimal.

  • Poxa mano, thanks a lot. I really hadn’t thought of that logic that take the whole part, Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.