Ruby Float negative()方法及示例
flo at negative() 是一个float类的方法,用于检查浮点数是否为负数。
语法: float.negative()
参数: 要检查的浮点数值
返回: 布尔值 如果值是正的,返回false;如果值是负的,返回true。
例子 #1 :
# Ruby code for negative() method
# Initializing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
# Printing result
puts "a is negative : #{a.negative?}\n\n"
puts "b is negative : #{b.negative?}\n\n"
puts "c is negative : #{c.negative?}\n\n"
输出:
a is negative : true
b is negative : true
c is negative : false
例子#2 。
# Ruby code for negative() method
# Initializing value
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
# Printing Result
puts "a is negative : #{a.negative?}\n\n"
puts "b is negative : #{b.negative?}\n\n"
puts "c is negative : #{c.negative?}\n\n"
输出:
a is negative : true
b is negative : false
c is negative : true