'How to get the exact number integer when the decimals are many in python?

When there are too many decimal values, the return is never the integer present in the value, but a higher one, how should I proceed so that this doesn't happen?


Adition using decimal:

from decimal import *
a = 2.999999999999999999999999999999999999
b = Decimal(str(a)).quantize(Decimal('1.'), rounding=ROUND_DOWN)
print(b)

Result 3 instead of the correct value that would be 2


a = 2.999999999999999999999999999999999999
b = str(a)[:str(a).find('.')]
print(b)

Result 3 instead of the correct value that would be 2

a = 2.999999999999999999999999999999999999
b= int(a)
print(b)

Result 3 instead of the correct value that would be 2

import math
a = 2.99999999999999999999999999
print(math.modf(a))

Result 3 instead of the correct value that would be 2

How should I proceed to always retrieve the correct integer?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source