Ruby float precision
问题 As I understand it, Ruby (1.9.2) floats have a precision of 15 decimal digits. Therefore, I would expect rounding float x to 15 decimal places would equal x . For this calculation this isn't the case. x = (0.33 * 10) x == x.round(15) # => false Incidentally, rounding to 16 places returns true. Can you please explain this to me? 回答1: Part of the problem is that 0.33 does not have an exact representation in the underlying format, because it cannot be expressed by a series of 1 / 2 n terms. So,