有没有遇到过数据计算得出的结果为xx.99999998情况?

小程序 文章 2020-08-07 13:41 608 0 全屏看文

AI助手支持GPT4.0

有没有遇到过数据计算得出的结果为xx.99999998情况?Have you ever encountered a situation where the result of data calculation is xx.99999998?

有没有遇到过数据计算得出的结果为xx.99999998情况?

例如:a=0.8;b=a;

a=0.8-0.04;

c=b-a=-0.039999999...

大部分时候进行简单的加减乘除就会造成这种结果,必须得添加个toFixed才能将小数点得到自己想要的结果,对于数据计算结果的小程序极其不友好

For example: a = 0.8; b = a; a = 0.8-0.04; C = B-A = - 0.03999999... Most of the time, simple addition, subtraction, multiplication and division will result in this result. You have to add a ToFixed to get the desired result of the decimal point, which is extremely unfriendly for small programs of data calculation results

回答:

张有釜:

推荐你个网站 whatfuckjs 里面收录了各种js的奇怪问题

微喵网络:

不是小程序的问题,js计算精度问题

搞文艺的猿:

这不跟正常嘛 二进制计算都这样

-EOF-

AI助手支持GPT4.0