新手问题 Ruby 怎样判断一个数字是整数还是小数?

easonlovejiven · February 27, 2015 · Last by msl12 replied at March 03, 2017 · 4524 hits

ruby 怎样判断一个数字是整数还是小数?

Now this will blow PO's mind:

puts 1.is_a? Integer
puts 2.5.is_a? Float
puts 2.5.is_a? Integer
puts 1.is_a? Float

楼主发了这么多贴了,还不知道怎么起标题?!

怎样发帖啊

a == a.to_i ? true : false
You need to Sign in before reply, if you don't have an account, please Sign up first.