public class A { /**
* @param args
*/
public static void main(String[] args) {
float a = 1367.0917f ;
int b = 1300 ;
System.out.println((a*10000-b*10000)/10000) ;
System.out.println(((a-b)*10000)/10000) ;
}}
* @param args
*/
public static void main(String[] args) {
float a = 1367.0917f ;
int b = 1300 ;
System.out.println((a*10000-b*10000)/10000) ;
System.out.println(((a-b)*10000)/10000) ;
}}
可以这么试:
float a = 1367.0917f ;
System.out.println(new DecimalFormat("0.00000000000000").format(a));
你就会发现很奇妙的现象。
所以只能用二进制来表示小数
所以像浮点数这种东西就会有精度的偏差 很正常