m*n
2 楼
RT,谢谢!
m*h
3 楼
来PK吧
k*n
4 楼
比如
Math.round(212999*1.5)=319499
Math.round(21299.9*10*1.5)=319499
但是
Math.round(2129.99*100*1.5) =319498
头大了。。
Math.round(212999*1.5)=319499
Math.round(21299.9*10*1.5)=319499
但是
Math.round(2129.99*100*1.5) =319498
头大了。。
v*n
7 楼
discover 1.5
k*n
8 楼
自己写了个简单的解决办法来round小数点后两位。。
return Math.round((Math.round(x*1000)/1000)*100)/100;
但遇到 9.9949 就不行了。。
还打算试试 Math.round(x*100+0.0000000001)/100
return Math.round((Math.round(x*1000)/1000)*100)/100;
但遇到 9.9949 就不行了。。
还打算试试 Math.round(x*100+0.0000000001)/100
o*r
12 楼
I think that it's something to do with the IEEE floating point standard used
in PCs. Not all float/double numbers can be stored precisely. For example,
1/3 can't be stored precisely. Mathematically, 1/3 + 1/3 + 1/3 = 1. But in
computer, it may not be true.
212999 * 1.5 = 319498.5
21299.9 * 10 * 1.5 = 319498.5
2129.99 * 100 * 1.5 = 319498.49999999994
Math.round works as follows:
- for >= 0.5, it rounds up.
- for < 0.5, it rounds down.
So if you add 0.5, the Math.round gives you the right result:
212999 * 1.5 + 0.5 = 319499 -> round to 319499
21299.9 * 10 * 1.5 + 0.5 = 319499 -> round to 319499
2129.99 * 100 * 1.5 + 0.5 = 319498.99999999994 -> round to 319499
in PCs. Not all float/double numbers can be stored precisely. For example,
1/3 can't be stored precisely. Mathematically, 1/3 + 1/3 + 1/3 = 1. But in
computer, it may not be true.
212999 * 1.5 = 319498.5
21299.9 * 10 * 1.5 = 319498.5
2129.99 * 100 * 1.5 = 319498.49999999994
Math.round works as follows:
- for >= 0.5, it rounds up.
- for < 0.5, it rounds down.
So if you add 0.5, the Math.round gives you the right result:
212999 * 1.5 + 0.5 = 319499 -> round to 319499
21299.9 * 10 * 1.5 + 0.5 = 319499 -> round to 319499
2129.99 * 100 * 1.5 + 0.5 = 319498.99999999994 -> round to 319499
p*e
13 楼
http://www.google.com/url?sa=t&source=web&rct=j&url=https://dev
用上面的Math.round10
Math.round(Math.round10(expr, -5))
-5是你要的精度
used
,
【在 o*********r 的大作中提到】
: I think that it's something to do with the IEEE floating point standard used
: in PCs. Not all float/double numbers can be stored precisely. For example,
: 1/3 can't be stored precisely. Mathematically, 1/3 + 1/3 + 1/3 = 1. But in
: computer, it may not be true.
: 212999 * 1.5 = 319498.5
: 21299.9 * 10 * 1.5 = 319498.5
: 2129.99 * 100 * 1.5 = 319498.49999999994
: Math.round works as follows:
: - for >= 0.5, it rounds up.
: - for < 0.5, it rounds down.
用上面的Math.round10
Math.round(Math.round10(expr, -5))
-5是你要的精度
used
,
【在 o*********r 的大作中提到】
: I think that it's something to do with the IEEE floating point standard used
: in PCs. Not all float/double numbers can be stored precisely. For example,
: 1/3 can't be stored precisely. Mathematically, 1/3 + 1/3 + 1/3 = 1. But in
: computer, it may not be true.
: 212999 * 1.5 = 319498.5
: 21299.9 * 10 * 1.5 = 319498.5
: 2129.99 * 100 * 1.5 = 319498.49999999994
: Math.round works as follows:
: - for >= 0.5, it rounds up.
: - for < 0.5, it rounds down.
相关阅读
一窝蜂学CS让人担心RTX 2080 Ti 的深学性能如何?李彦宏称"百度没有占便宜,有信心再赢一次"四名马农被枪杀, 因为提交的代码不合格 (转载)Service Mesh大家用的多吗?[bssd]美国大学生数学建模竞赛拿数学函数说FP,那么西格玛函数不就是for loop吗?AutoML难点在哪里?现在机器学习的都用什么语言了evolutionary-algorithm-outperforms-deep-learning-machines-[bssd]我觉得我可以摆摊算卦了。该怎么推导下面算法时间复杂度O(N!*N)的*N?魏老师你的瓷砖算法有人写了弱问个 aws 问题无意中发现个小巨牛啊数据库里的B+树为啥要用个指针把最底层的相邻叶节点连起来?想做一些open source的project你们看了国内那个公式相声吗Re: 为什么微软现在软件质量这么差了?线性代数学的好的进来一下 (转载)