Created
June 3, 2019 05:52
-
-
Save huangang/368deddfd27c8fa74b2ba972d2f01b6d to your computer and use it in GitHub Desktop.
js 解决 0.28 * 100 = 28.000000000000004
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
/** | |
* 解决 0.28 * 100 = 28.000000000000004 | |
* @param {*} num | |
* @param {*} precision | |
*/ | |
function strip (num, precision = 12) { | |
return +parseFloat(num.toPrecision(precision)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment