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
Stanislav O. 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)
=> true3.0.is_a?(Fixnum)
=> false3.0.is_a?(Integer)
=> false3.0.is_a?(Float)
=> true3.0.is_a?(Numeric)
=> true
2010/6/15 Stanislav O. [email protected]
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 advancePosted via http://www.ruby-forum.com/.
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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hey,
On Tuesday 15 June 2010, Stanislav O. [email protected]
wrote:
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkwXoaUACgkQhS0drJ3goJLPgwCfbiFIMLRWNkskgnOSRAS6MNLC
vbkAnAgG5EJskR+JwijDs3HRvV2Iz+AH
=DVcg
-----END PGP SIGNATURE-----