-2

Why Decimal(0.01) is equal Decimal('0.01000000000000000020816681711721685132943093776702880859375')

Tomasz Brzezina
  • 1,452
  • 5
  • 21
  • 44

1 Answers1

2

There is a big difference between Decimal('0.01') and Decimal(0.01).

First converts str into Decimal (and Decimal('0.01') is equal Decimal('0.01'),

Second converts float into Decimal (that's why Decimal(0.01) is equal Decimal('0.01000000000000000020816681711721685132943093776702880859375')

Tomasz Brzezina
  • 1,452
  • 5
  • 21
  • 44
  • I don't understand the logic of deletion questions and answers which explains exact problem. Nobody would look for FLOATING POINT MATH BROKEN in Decimal(0.01). I solved the problem when I discover that 0.01 is a float. But earlier it was very confusing. – Tomasz Brzezina Sep 15 '21 at 12:42
  • 1
    I'm with you man. Although this information is in the duplicate question, it is buried deep in an answer with few upvotes, so I think it's worth having this specific question and your answer. But not everyone agrees with me on this. – joanis Sep 15 '21 at 13:52
  • But there are too many questions are about floating point numbers being "broken" in every language, so I understand the rapid closing of such questions with a pointer to that question with its very detailed answers. – joanis Sep 15 '21 at 13:54