From: Vu Nang Luc Date: 2007-08-10T10:20:08+09:00 Subject: Re: precision loss with pack/unpack ? On 10 Tha ng T�m, 02:06, "Luis Parravicini" wrote: >And the result is different from the original > value. > > ------------ > a = 0.1234567 > b = [a].pack('g').unpack('g')[0] > > puts "#{a} =? #{b} => #{a == b}" > ------------ > > outputs: > > 0.1234567 =? 0.123456701636314 => false > It's quite common with float or double representation. Because float/ double can not represent ALL value within its range so some loss precision happens. It may happen right after assignment: eg: On my machine: > a = a= 100.1001001003333 >a 100.100100100333 (the last digit gone?)