Ruby Float nan?()方法及示例
Float nan?() 是一个float类方法,用于检查数值是否’不是一个数字’。Not A Number’意味着一个无效的IEEE浮点数。
语法: float.nan?()
参数: 要传递的浮点数
返回: 返回true – 如果值是’不是一个数字’,否则返回false
例子 #1 :
# Ruby program for nan?() method
# Initializing value
a = 0.0
b = 0.0.modulo(4.0)
# Printing result
puts "a is not_a_number : #{a.nan?}\n\n"
puts "b is not_a_number : #{b.nan?}\n\n"
输出:
a is not_a_number : false
b is not_a_number : false
例子#2 。
# Ruby program for nan?() method
# Initializing value
a = 26.00
b = 8.0
# Printing Result
puts "a is not_a_number : #{a.nan?}\n\n"
puts "b is not_a_number : #{b.nan?}\n\n"
输出:
a is not_a_number : false
b is not_a_number : false