Created
November 23, 2015 07:57
-
-
Save motss/03c138d7f25fc4631316 to your computer and use it in GitHub Desktop.
Javascript Floating Point Precision Issue
This file contains 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
// Example 1. | |
var firstFloatingPointNumber = 1.0; | |
var secondFloatingPointNumber = 0.7; | |
var result = firstFloatingPointNumber - secondFloatingPointNumber; // 0.30000000000000004, instead of 0.3. | |
// To fix that precision issue. | |
result = (firstFloatingPointNumber - secondFloatingPointNumber)/ 10; // 0.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment