Zoran Regvart
7/8/2008 8:51:00 AM
Hi,
On Tue, Jul 8, 2008 at 10:39 AM, Hyun chul Park <paxcholy@gmail.com> wrote:
> hi.
> i'm confused by float point calculation.
> like this!
>
> ------------------------------------------
> irb(main):001:0> 123.6 - 123
> => 0.599999999999994
>
> ------------------------------------------
>
> how to i get result 0.6 ?
try using BigDecimal, like:
irb(main):001:0> require 'bigdecimal'
=> true
irb(main):002:0> x = BigDecimal("123.6") - BigDecimal("123")
=> #<BigDecimal:8b13c,'0.6E0',4(16)>
irb(main):003:0> x.to_f
=> 0.6
zoran
--
Human by day user by night