Tag: 钱包

如何防止Ruby钱浮点错误

我正在使用带有money-rails gem的Rails来处理钱列。 有没有办法防止浮点错误发生? (即使是黑客也会这样做,我只是想确保没有这样的错误呈现给最终用户) Rspec示例案例: it “correctly manipulates simple money calculations” do # Money.infinite_precision = false or true i’ve tried both start_val = Money.new(“1000”, “EUR”) expect(start_val / 30 * 30).to eq start_val end 结果 Failure/Error: expect(start_val / 30 * 30).to eq start_val expected: # got: # (compared using ==) Diff: @@ -1,2 +1,2 @@ -# […]