显示数字小数结果不正确,方法无错误
public class A
{
public static void main(String[] args)
{
double num= 256.879;
System.out.println("the result is: "+ fracPart(num));
}
public static double fracPart(double x)
{
return x- whole(x);
}
public static int whole(double y)
{
return (int)y ;
}
}
电脑结果显示不是0.879 而是0.87900000000000191
将数字换成256.967 不是显示0.967 而是 0.96699999999999845
这是为什么?