can anyone please explain how 2.8 modulo 2 is 0.7999999999999998?

185 Views Asked by At

I am not a mathematician, and just started programming in javascript and wonders how 2.8 % 2 = 0.7999999999999998.
Note: I know it is remainder operation.
May be I forgot my school mathematics concepts. Can anyone please explain this? Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

The floating point number 2.8 cannot be exactly represented in your Javascript floating point number: the binary64 IEEE double precision number is $$2.8 \rightarrow 2.79999999999999982236431605997495353221893310546875\dots$$