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


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


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

用法: 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


相关用法


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