Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Conversion of a large float to an int

Suppose I have this large number,x

3333333333333333333333333333333333333333333333333333333333333 (which I want)

and this large number,n
3333333333333333333333333333333333333333333333333333333333333.0.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When I convert n into an int through the round function, it provides me with a completely different number, which I suppose is because of floating point precision limitations.

Is there anyway to round of that number into a integer. I don’t have to worry about any other decimal points, just .0.

>Solution :

from decimal import Decimal

print(int(Decimal("3333333333333333333333333333333333333333333333333333333333333.0")))

Output:

3333333333333333333333333333333333333333333333333333333333333
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading