当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby Float positive()用法及代码示例


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

用法:float.positive()

参数:要检查的浮点值


返回:布尔值返回true-如果值是正数,则返回false-如果值是负数

范例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


相关用法


注:本文由纯净天空筛选整理自mayank5326大神的英文原创作品 Ruby Float positive() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。