Android中的Math.round(),Math.floor(),Math.ceil()方法区别

  • Math.round()方法: 表示的是“四舍五入”计算。
    Math.round(1.5) = 2
    Math.round(-1.5) = -1

  • Math.floor()方法: 表示的是“向下取整”计算。
    Math.floor(1.7) = 1.0
    Math.floor(-1.2) = -2.0

  • Math.ceil()方法: 表示的是“向上取整”计算。
    Math.ceil(1.3) = 2.0
    Math.ceil(-1.7) = -1.0

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容