首页 > 编程知识 正文

java怎么取整数,java 除法取整

时间:2023-05-04 05:00:47 阅读:20019 作者:322

使用java进行四舍五入操作有四种方法:

公共统计双精度//向上舍入

第一个: ceil是天花板的意思,表示向上调整。 测试:

系统. out.println (math.ceil (1.01 );

系统. out.println (math.ceil (-1.01 );

系统. out.println (math.ceil (1.5 );

系统. out.println (math.ceil (-1.5 );

输出结果:

2.0

-1.0

2.0

-1.0

第二个: floor是地板的意思,表示向下整理。 测试:

系统. out.println (math.floor (1.01 );

输出: 1.0

第三,round执行的是数学四舍五入执行。 通过查看源代码,可以看到它与floor方法的关系。 测试:

第四个:最有趣的是返回最接近参数的整数,如果两个数一样接近,则返回偶数。 1 )有两种特殊情况:如果参数本身是整数,则返回其本身。

2 )如果不是数字、无限大或正负0,结果就是本身。

returnsthedoublevaluethatisclosestinvaluetotheargumentandisequaltoamathematicalinteger.iftwodoublevaluesthataremathematicalical ose,theresultistheintegervaluethatiseven.special cases 3360

iftheargumentvalueisalreadyequaltoamathematicalinteger,thentheresultisthesameastheargument。

iftheargumentisnanoraninfinityorpositivezeroornegativezero,thentheresultisthesameastheargument。

参数: a双精度值。

returns 3360 theclosestfloating-pointvaluetoathatisequaltoamathematicalinteger。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。