Some `BigDecimal` values don't match with `Float`

Viewed 1954

Some BigDecimal values can be compared with a Float by eq in Rspec3, but some values can't be.

describe "compare BigDecimal with Float" do
    it { expect("83.79".to_d).to eq(83.79) } # => fail
    it { expect("83.75".to_d).to eq(83.75) } # => succeed
end

To avoid error, I'm using expressions like eq("83.79".to_d).

Why does the first test fail while the second succeeds?

2 Answers
Related