Why 4.1%2 returns 0.0999999999999996 using Ruby?But 4.2%2==0.2
问题 Why 4.1%2 returns 0.0999999999999996?But 4.2%2==0.2. 回答1: See here: What Every Programmer Should Know About Floating-Point Arithmetic Real numbers are infinite. Computers are working with a finite number of bits (32 bits, 64 bits today). As a result floating-point arithmetic done by computers cannot represent all the real numbers. 0.1 is one of these numbers. Note that is not an issue related to Ruby, but to all programming languages because it comes from the way computers represent real