📜  Ruby Floatnegative() 方法与示例

📅  最后修改于: 2022-05-13 01:54:33.912000             🧑  作者: Mango

Ruby Floatnegative() 方法与示例

Floatnegative()是一个浮点类方法,用于检查浮点值是否为负。

示例 #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