0

https://i.stack.imgur.com/mKKXL.png

Why 0.03 divide by 0.01, the reminder is 0.01, not zero??

I try 0.3 % 0.1, the result is 0.1. For 3 % 1, the result is zero. Crazy.

Corralien
  • 109,409
  • 8
  • 28
  • 52
wen wu
  • 11
  • 1
  • You should go one step deeper. The number corresponding to input/display 0.01 is `"%.25f"%0.01 : '0.0100000000000000002081668'` and for 0.03 `"%.25f"%0.03 : '0.0299999999999999988897770'` – Lutz Lehmann Feb 14 '23 at 15:08

1 Answers1

1

Use remainder can avoid this error, as shown below.

from math import remainder
remainder(0.03,0.01)
Corralien
  • 109,409
  • 8
  • 28
  • 52
wen wu
  • 11
  • 1