浮點數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
相關用法
- Ruby Float quo()用法及代碼示例
- Ruby Float zero?()用法及代碼示例
- Ruby Float eql()用法及代碼示例
- Ruby Float arg()用法及代碼示例
- Ruby Float nan?()用法及代碼示例
- Ruby Float rationalize()用法及代碼示例
- Ruby Float to_i()用法及代碼示例
- Ruby Float magnitude()用法及代碼示例
- Ruby Float fdiv()用法及代碼示例
- Ruby Float phase()用法及代碼示例
- Ruby Float round()用法及代碼示例
- Ruby Float floor()用法及代碼示例
- Ruby Float next_float()用法及代碼示例
- Ruby Float coerce()用法及代碼示例
- Ruby Float denominator()用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby Float positive() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。