floor()是Ruby中的内置函数,返回小于或等于rat的最大数字,精度为n位十进制数字。 ndigits默认为0。当ndigits为正数时,它返回有理数,否则返回整数。
用法: rat.floor(ndigits)
参数:该函数接受单个参数
返回值:返回小于或等于rat的最大数字,精度为n位数字小数位
例子1:
# Ruby program for floor() method 
  
# Initialize rational number 
rat1 = Rational(-4, 3) 
  
# Prints the rational number 
puts rat1.floor()输出:
-2
例子2:
# Ruby program for floor() method 
  
# Initialize rational number 
rat1 = Rational('123.456') 
  
# Prints the rational number 
puts rat1.floor(1) 
puts rat1.floor(-1)输出:
617/5 120
相关用法
- Ruby Rational quo()用法及代码示例
- Ruby Rational abs()用法及代码示例
- Ruby Rational negative?()用法及代码示例
- Ruby Rational positive?()用法及代码示例
- Ruby Rational to_s()用法及代码示例
- Ruby Rational truncate()用法及代码示例
- Ruby Rational denominator()用法及代码示例
- Ruby Rational fdiv()用法及代码示例
- Ruby Rational to_f()用法及代码示例
- Ruby Rational to_i()用法及代码示例
- Ruby Rational to_r()用法及代码示例
- Ruby Rational rationalize()用法及代码示例
- Ruby Rational round()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Ruby | Rational floor() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
