Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strip 不生效 #39

Open
joey-lucky opened this issue Sep 9, 2020 · 3 comments
Open

strip 不生效 #39

joey-lucky opened this issue Sep 9, 2020 · 3 comments

Comments

@joey-lucky
Copy link

joey-lucky commented Sep 9, 2020

const NP = require("number-precision");
console.log(0.151 - 0.145);// 0.006000000000000005
console.log(NP.strip(0.151-0.145)); //0.00600000000000001
@reason211
Copy link

function strip(num, precision=15) {
return +parseFloat(Number(num).toPrecision(precision));
}

precision默认改成14,可以解决你的这个问题😂

@joey-lucky
Copy link
Author

function strip(num, precision=15) {
return +parseFloat(Number(num).toPrecision(precision));
}

precision默认改成14,可以解决你的这个问题😂

好的,感谢!!

@EchoWht
Copy link

EchoWht commented Jan 29, 2021

const NP = require("number-precision");
console.log(0.151 - 0.145);// 0.006000000000000005
console.log(NP.strip(0.151-0.145)); //0.00600000000000001

请教一下,这种情况直接用精确减法是不是好一些
console.log(NP.minus(0.151,0.145));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants