本文介紹了如何在 Java 中舍入整數(shù)除法并獲得 int 結(jié)果?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我剛剛寫了一個小方法來計算手機短信的頁數(shù).我沒有選擇使用 Math.ceil
進(jìn)行四舍五入,老實說,它看起來很丑.
I just wrote a tiny method to count the number of pages for cell phone SMS. I didn't have the option to round up using Math.ceil
, and honestly it seems to be very ugly.
這是我的代碼:
我不太喜歡這段代碼,我正在尋找一種更優(yōu)雅的方式來做這件事.有了這個,我期待 3 而不是 3.0000000.有什么想法嗎?
I don't really like this piece of code and I'm looking for a more elegant way of doing this. With this, I'm expecting 3 and not 3.0000000. Any ideas?
推薦答案
你可以使用整數(shù)除法來四舍五入
To round up an integer division you can use
或者如果兩個數(shù)字都是正數(shù)
or if both numbers are positive
這篇關(guān)于如何在 Java 中舍入整數(shù)除法并獲得 int 結(jié)果?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!