Floating point multiplication in java [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to round a number to n decimal places in Java When multiplying two numbers in java happens this: double a = 9.495 * 100; Expected result: a = 949.5; But the obtained result is: a = 949.4999999999999 When I try to round number 9.495 in two decimal places the result is 9.49 instead of 9.50 Any ideas how to solve this problem? 回答1: If you want accurate floating point computations, do not use the float or double