Math.ceil and Math.floor returning same value

前端 未结 5 714
萌比男神i
萌比男神i 2020-12-31 00:31

I have a double (23.46)

And using the methods Math.ceil and Math.floor and parsing my double to these methods, I get the same value returned to me, which is 23...

5条回答
  •  轮回少年
    2020-12-31 01:31

    float x = ((float)2346/100);  // You should type cast. Otherwise results 23
    Math.ceil(x);                 // So Math.ceil(23) is 23 !!!
                                  // Here I type cast to float.
                                  // So I get the result 24
    

提交回复
热议问题