caidanhui

java中提供三种小数取整方式

  1. Math.ceil()  
  2. Math.floor()
  3. Math.round()

 

ceil:天花板,向上quzheng

  Math.ceil(11.5) = 12

  Math.ceil(-11.5) = -11

floor:地,向下取整

  Math.floor(11.5) = 11

  Math.floor(-11.5) = -12

round:4舍5入

  Math.round(x + 0.5),再向下取整

  当 x = 11.5 时,Math.round(x + 0.5) = Math.round(12) = 12

  当 x = -11.5时,Math.round(x + 0.5) = Math.round(-11) = -11

分类:

技术点:

相关文章:

  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2021-11-12
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2021-11-23
  • 2021-07-31
  • 2021-05-20
  • 2021-07-18
  • 2022-12-23
  • 2021-07-24
相关资源
相似解决方案