Java 向上舍入任意數字 - Java Round up Any Number

問題:

I can't seem to find the answer I'm looking for regarding a simple question: how do I round up any number to the nearest int ?我似乎無法找到我正在尋找的關於一個簡單問題的答案:如何將任何數字四捨五入到最接近的int

For example, whenever the number is 0.2, 0.7, 0.2222, 0.4324, 0.99999 I would want the outcome to be 1.例如,當數字是 0.2、0.7、0.2222、0.4324、0.99999 時,我希望結果爲 1。

So far I have到目前爲止我有

int b = (int) Math.ceil(a / 100);

It doesn't seem to be doing the job, though.不過,它似乎並沒有完成這項工作。


解決方案:

參考一: https://en.stackoom.com/question/J3Eq
參考二: https://stackoom.com/question/J3Eq
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章