Why different result? float vs double [duplicate]
问题 This question already has answers here : Float and double datatype in Java (9 answers) Is floating point math broken? (31 answers) Closed 12 months ago . System.out.println(0.1F + 0.2F); // 0.3 System.out.println(0.1D + 0.2D); // 0.30000000000000004 I understood 0.1D + 0.2D ~= 0.30000000000000004. But I guessed these result are same, but it is not. Why result are different? 回答1: Why are the results different? In a general sense: Because the binary representations for float and double are