Ruby Integer 整数?示例函数
整数? Ruby 中的函数返回一个布尔值。如果数字是 int 则返回 true,否则返回 false。
Syntax: number.integer?
Parameter: The function takes the integer which is to be checked for int or not.
Return Value: The function returns a boolean value which determines if the value is int or not.
示例 #1:
# Ruby program of Integer integer? function
# Initializing the numbers
num1 = 22
num2 = 15.555
num3 = 19.978
num4 = 20
# Prints if integer or not
puts num1.integer?
puts num2.integer?
puts num3.integer?
puts num4.integer?
输出:
true
false
false
true
示例 #2: :
# Ruby program of Integer integer? function
# Initializing the numbers
num1 = 89.76
num2 = -100
num3 = 100
num4 = 29.78
# Prints if integer or not
puts num1.integer?
puts num2.integer?
puts num3.integer?
puts num4.integer?
输出:
false
true
true
false