Math.round(double) 四舍五入成long,强制转成int就可以了。
Math.round(float) 四舍五入成int
天花板和地板函数得到的是#.0类型的double,再强制转成int
天花板函数:Math.ceil(double)
地板函数:Math.floor(double)
本文详细介绍了Java中使用Math类进行数学运算的方法,包括四舍五入、取整等操作的具体实现方式。通过实例展示了如何利用Math.round, Math.ceil 和 Math.floor 函数处理浮点数,确保读者能够正确掌握这些常用数学函数的应用。
Math.round(double) 四舍五入成long,强制转成int就可以了。
Math.round(float) 四舍五入成int
天花板和地板函数得到的是#.0类型的double,再强制转成int
天花板函数:Math.ceil(double)
地板函数:Math.floor(double)

被折叠的 条评论
为什么被折叠?