How can 1/100=0

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>

On Feb 8, 5:06 pm, Junkone [email protected] 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

On Feb 8, 2008, at 11:10 AM, 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>

Integer division.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

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>

Try 1.0/100.0

On Feb 8, 11:09 am, Paolo B. [email protected] wrote:

in what languages it isn’t?
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 ???

On Feb 8, 2008 5:24 PM, Junkone [email protected] wrote:

should 1/100=.01 ???

Like said, it is about integer division. If you divide an integer
with another integer you’ll get the integer result:

5 / 2
=> 2
If you have a float in the term, the result becomes a float
1.0 / 100
=> 0.01
1 / 100.0
=> 0.01

On Feb 8, 5:20 pm, Junkone [email protected] wrote:

irb(main):002:0> TRAILING_STOP
0
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