Skip to content

Instantly share code, notes, and snippets.

@huangang
Created June 3, 2019 05:52
Show Gist options
  • Save huangang/368deddfd27c8fa74b2ba972d2f01b6d to your computer and use it in GitHub Desktop.
Save huangang/368deddfd27c8fa74b2ba972d2f01b6d to your computer and use it in GitHub Desktop.
js 解决 0.28 * 100 = 28.000000000000004
/**
* 解决 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