Check Fixnum

Hi
I have Fixnum. I want to check does this value integer or float, i. e.
has .xx in the trail or not. How can I check this?
Thanks in advance

···

--
Posted via http://www.ruby-forum.com/.

Stanislav Orlenko wrote:

I have Fixnum. I want to check does this value integer or float, i. e.
has .xx in the trail or not. How can I check this?

"Fixnum" means "fixed point", or really "small integer": a Fixnum can
never be a float.

$ irb --simple-prompt

3.is_a?(Fixnum)

=> true

3.0.is_a?(Fixnum)

=> false

3.0.is_a?(Integer)

=> false

3.0.is_a?(Float)

=> true

3.0.is_a?(Numeric)

=> true

···

--
Posted via http://www.ruby-forum.com/\.

Hey,

Hi
I have Fixnum. I want to check does this value integer or float, i. e.
has .xx in the trail or not. How can I check this?
Thanks in advance

Mathematically by doing a modulo division by 1:

- ---%<---
irb(main):001:0> i = 5
=> 5
irb(main):002:0> j = 5.2
=> 5.2
irb(main):003:0> j %1
=> 0.2
irb(main):004:0> i%1
=> 0
- --->%---

HTH.
      Eric

···

On Tuesday 15 June 2010, Stanislav Orlenko <orlenko.stas@gmail.com> wrote:

check your reference...
Fixnum are Integers, not float...
you are probably mislead by Numeric... because Integer and Float are
Numeric

a = 0.1
a.class
=> Float

b = 1
b.class
=> Fixnum

a.is_a? Numeric
=> true

b.is_a? Numeric
=> true

···

2010/6/15 Stanislav Orlenko <orlenko.stas@gmail.com>

Hi
I have Fixnum. I want to check does this value integer or float, i. e.
has .xx in the trail or not. How can I check this?
Thanks in advance
--
Posted via http://www.ruby-forum.com/\.