JavaScript Bug – Modulo of small numbers

It seems that there is a problem with the modulo function, ‘%’, in JavaScript.

For example: 10 % 0.1 should equate to zero but comes out as 0.09999999999999945 probably due to some internal floating-point rounding errors.

Easy solution (a hack really): Multiply both numbers by 1000 before using the modulo function.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.