java double精度问题

import java.text.*;
public class DoubleTest
{
    public static void main(String[] args)
    {
        DecimalFormat format = new DecimalFormat("0.0");
        double a = 1.9;
        double b = 0.3;
        //此时a+b是2.1999999999999997
        double d = Double.valueOf(format.format(a + b));
        System.out.println(a+"+"+b+"="+d);//这样就是2.2了
    }
}

你可能感兴趣的:(java)