Last active
November 12, 2020 11:30
-
-
Save codejockie/7d4468e2bd018e2a2de65836e0c18e4e to your computer and use it in GitHub Desktop.
How to handle JS modulus operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The following fixes the inconsisties in the JS % (modulus) operator when used on fractional numbers | |
| // Example 1 | |
| // Multiply both sides of operand by 10000 | |
| let remainder = (100 * 10000) % (0.33 * 10000); | |
| // Example 2 | |
| // Divide the numbers, then apply the modulus of result by 1 | |
| remainder = (100 / 0.33) % 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment