0
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by Najib Idrissi, S.C.B., Ian Miller, Patrick Stevens, Dietrich Burde Mar 24 '16 at 13:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ What do you mean with modulo? $\endgroup$ – Martín Vacas Vignolo Mar 24 '16 at 12:37
  • $\begingroup$ That is just a glitch caused by the floating point system. $\endgroup$ – Sangchul Lee Mar 24 '16 at 12:39
  • $\begingroup$ Are you wondering why it isn't $0.8$ like it should be or are you confused about the modulo operation? $\endgroup$ – Nikunj Mar 24 '16 at 12:39
  • $\begingroup$ Are you asking why computers do not represent floating point numbers exactly, or why $2.8 = 0.8\bmod 2$? $\endgroup$ – almagest Mar 24 '16 at 12:40
  • $\begingroup$ modulo is remainder operator. here in my question if we divide 2.8 by 2, then we are getting remainder 0.7999999999999998. do you know how? or i think it is programming related doubt. i expect the answer should be 0.8. $\endgroup$ – jsingh Mar 24 '16 at 12:41
8
$\begingroup$

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$$

$\endgroup$
  • $\begingroup$ oh thanks a lot, now i got it. answer is simple and clear. $\endgroup$ – jsingh Mar 24 '16 at 12:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.