📜  Ruby Float positive() 方法与示例

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

Ruby Float positive() 方法与示例

Float positive() 是一个浮点类方法,用于检查浮点值是否为正。

示例 #1:

# Ruby program for positive() method
  
# Initialing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
  
# Printing result
puts "a is positive : #{a.positive?}\n\n"
puts "b is positive : #{b.positive?}\n\n"
puts "c is positive : #{c.positive?}\n\n"

输出 :

a is positive : false

b is positive : false

c is positive : true

示例 #2:

# Ruby code for positive() method
  
# Initializing value 
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
  
# Printing result
puts "a is positive : #{a.positive?}\n\n"
puts "b is positive : #{b.positive?}\n\n"
puts "c is positive : #{c.positive?}\n\n"


输出 :

a is positive : false

b is positive : true

c is positive : false