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


Ruby Integer.ceil用法及代码示例


本文简要介绍ruby语言中 Integer.ceil 的用法。

用法

ceil(ndigits = 0) → integer

返回大于或等于 self 的最小数字,精度为 ndigits 十进制数字。

当精度为负时,返回值是一个至少有 ndigits.abs 尾随零的整数:

555.ceil(-1)  # => 560
555.ceil(-2)  # => 600
-555.ceil(-2) # => -500
555.ceil(-3)  # => 1000

ndigits 为零或正数时返回self

555.ceil     # => 555
555.ceil(50) # => 555

相关: Integer#floor

相关用法


注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Integer.ceil。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。