denominator()是Ruby中的內置函數,返回的分母始終為正。
用法: rat.denominator()
參數:該函數不接受任何參數
返回值:它返回始終為正的分母。
例子1:
# Ruby program for denominator() method
# Initialize rational number
rat1 = Rational(7, -3)
# Prints the rational number
puts rat1.denominator()
輸出:
3
例子2:
# Ruby program for denominator() method
# Initialize rational number
rat1 = Rational(7)
# Prints the rational number
puts rat1.denominator()
輸出:
1
相關用法
- Ruby Complex denominator用法及代碼示例
- Ruby Numeric denominator()用法及代碼示例
- Ruby Rational abs()用法及代碼示例
- Ruby Rational quo()用法及代碼示例
- Ruby Rational round()用法及代碼示例
- Ruby Rational positive?()用法及代碼示例
- Ruby Rational negative?()用法及代碼示例
- Ruby Rational rationalize()用法及代碼示例
- Ruby Rational inspect()用法及代碼示例
- Ruby Rational numerator()用法及代碼示例
- Ruby Rational fdiv()用法及代碼示例
- Ruby Rational to_i()用法及代碼示例
- Ruby Rational floor()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Rational denominator() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。