Ruby BigDecimal generate plain float number? -


I have just changed my ruby ​​version to 1.9.2, and the Bugattycam code in Ruby 1.8 is no longer working . Here the test code has been shown that

  irb (main): 001: 0> Expected 'bigdecimal' = & gt; True IRB (Main): 002: 0> (BigDiscell.New ("1") / BigDescale.New ("3") To_s ("F") => "0.33333333" irb (main): 003: 0> (BigDecell.New ("1 ToDs ("F") => 
"0.33333333"

Problems with my Ruby installation? Otherwise, It seems that Ruby 1.9 should also work on the test code, what's going on here?

It seems that changes in Ruby 1.9 '/' will not get significant points specified from two operators, which work in Ruby 1.8 The above code will not work, because for '/', only two operands will be on Digitally important, and it will always generate float number and float number using the '/' method always. < Instead, in that case, I should use the div (value, number)

  (BigDecimal.new ("1", 20) .div (BigDecimal. To ("3", 20), 50). To_s ("F") => "0.33333333333333333333333333333333333333333333333333"  

Hope to make that.


Comments