-:total_cost_with_tax => #<BigDecimal:7fda9d17aaf0,'0.105225E4',18(45)>,
-:total_cost_without_tax => #<BigDecimal:7fda9d17b450,'0.972E3',9(36)>,
-:total_last_installment_amount => #<BigDecimal:7fda9d17b978,'0.8011E2',18(45)>,
-:total_monthly_installment_amount => #<BigDecimal:7fda9d17abb8,'0.8011E2',18(45)>,
-:total_tax => #<BigDecimal:7fda9d17b068,'0.8025E2',18(45)>,
+:total_cost_with_tax => #<BigDecimal:7fda9d0184c8,'0.105225E4',18(36)>,
+:total_cost_without_tax => #<BigDecimal:7fda91ff2b48,'0.972E3',9(27)>,
+:total_last_installment_amount => #<BigDecimal:7fda91fee548,'0.8011E2',18(36)>,
+:total_monthly_installment_amount => #<BigDecimal:7fda91fe72c0,'0.8011E2',18(36)>,
+:total_tax => #<BigDecimal:7fda9d00a2b0,'0.8025E2',18(36)>,
因此,這些都是散佈在我的一些測試... rspec 2,rails 3.我使用.should eq()
來比較散列來比較。我似乎無法得到正確的咒語。看起來這是一件精確的事情,看起來很愚蠢。rspec大十進制匹配器
爲了記錄在案:不正確的。 usijng BigDecimal的全部意義在於它不會像Float那樣行事;你應該得到你輸入的號碼。 – 2016-01-15 14:42:39
@Andy我添加了更多的細節來解決你的評論。 – joelparkerhenderson 2016-01-15 22:48:20
非常好,但我的評論的觀點是,你不應該*需要*使用'be_within'來匹配一個BegDecimal。這不像一個浮動;由於數字的存儲方式,您無需考慮舍入錯誤。 – 2016-01-18 08:58:12