From: Paolo Bonzini Date: 2008-02-09T01:59:56+09:00 Subject: Re: how can 1/100=0 On Feb 8, 5:20 pm, Junkone wrote: > On Feb 8, 11:09 am, Paolo Bonzini wrote: > > > > > On Feb 8, 5:06 pm, Junkone wrote: > > > > cannot belive my eyes. how can 1/100 be equal to 0. > > > E:\Documents and Settings\Roasty>irb > > > irb(main):001:0> TRAILING_STOP=1/100 > > > => 0 > > > irb(main):002:0> TRAILING_STOP > > > => 0 > > > irb(main):003:0> > > > in what languages it isn't? > > > $ python > > Python 2.5.1 (r251:54863, May 12 2007, 11:15:25) > > [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin > > Type "help", "copyright", "credits" or "license" for more information.>>> 1/100 > > > 0 > > > (and C too, though I won't write the program here). > > > anyway, you can have 1/100 return a rational: > > > $ irb > > irb(main):001:0> require 'mathn' > > => true > > irb(main):002:0> 1/100 > > => 1/100 > > irb(main):003:0> (1/100).denominator > > => 100 > > > Paolo > > should 1/100=.01 ???? Even in C, 1/100 = 0. But 1.0/100.0 or 1.0/100 or 1/100.0 = 0.01 because the division is done in floating-point math. Paolo