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.
相关阅读
Help~~~再来问个蠢问题Question on C++ Access Control (protected)请问:稀疏矩阵运算有什么好的C++库?大家编程用得algebra lib是什么? (转载)How to sort a map in C++ STL based on Value, instead of Keya g++ new exceptions questionHow to initialize object in constructor?两把门锁的问题perl:里有象 c assert 的东西吗?Matlab中,如何沿着某个方向读取二维矩阵中的数据a c++ questionHelp! Virtual Destructor问个习惯问题Comments about OOM killer, for fun only :)时间格式转换的问题Excel Marco如何看一共有多少行程序Need suggestions from your experts!!求助:Wavelet 的 library (转载)