0

I have a long float - e.g. 3.2222232546222222222222222222222222222222

When I check to see if it is less than a certain amount through len(str(mynum)), it truncates the amount.

So python defaults my number to 3.222223254622222 when i do str(mynum)

Hanuman95
  • 89
  • 7
  • 3.2222232546222222222.. and 3.222223254622222 are indistinguishable when stored in `float` type. That's why you cannot see any extra digits. The problem is unsolvable as it is. – Zefick Feb 03 '20 at 17:02
  • You have a long float *literal*, which maps to the same value of type `float` as many other float literals. – chepner Feb 03 '20 at 17:03
  • If you need more precision than the standard `float` type, see the `decimal` module: https://docs.python.org/3/library/decimal.html – bg2b Feb 03 '20 at 17:06
  • The problem with Decimal is that it adds on random digits to the end of the number, and I need to test the raw number I'm pulling in to check if it's less than a certain amount of digits. Is there another workaround? – Hanuman95 Feb 03 '20 at 20:02
  • @VinceStone `x=Decimal('3.2222232546222222222222222222222222222222')` should not be adding any extra stuff. If you're writing `x=Decimal(3.2222232546222222222222222222222222222222)`, your problem is that you've already lost the relevant information by the time the `Decimal` is created. – bg2b Feb 03 '20 at 20:56

0 Answers0