fork download
  1. require "bigdecimal"
  2.  
  3. x = "8.95"
  4. puts x.to_f # 8.95 <- ok
  5. puts 8.95.to_f # 8.95 <- ok
  6. puts x.to_f * 100 # 894.9999999999999 say wha?
  7.  
  8. puts (x.to_f * 100.0).to_i # 894 <- nope
  9. puts (BigDecimal("8.95") * 100).to_i # 895 <- this is what i was looking for
Success #stdin #stdout 0s 6624KB
stdin
Standard input is empty
stdout
8.95
8.95
894.9999999999999
894
895