I get this result:
8.01 - 8.0 #=> 0.009999999999999787
I want my answer to be 0.01
. What can I do to fix this? How can I get this to happen? I guess this is float math. Is this due to floating point precision?
I get this result:
8.01 - 8.0 #=> 0.009999999999999787
I want my answer to be 0.01
. What can I do to fix this? How can I get this to happen? I guess this is float math. Is this due to floating point precision?
You can use Ruby's arbitrary-precision decimal data type, BigDecimal
:
BigDecimal.new("8.01") - BigDecimal.new("8") # => 0.1e-1