Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のコードがあります。
int total = 6; int perPage = 5; double pages = total/perPage; double ceilPages = Math.ceil(pages); out.println(ceilPages);
どの出力1.0.
1.0
の結果が2.0なので、出力するべきだと思いました。total/perPage1.2
2.0
total/perPage
1.2
に切り上げられないのはなぜ2.0ですか?
整数除算の結果を double にキャストしています。
結果の前に、除算の各部分を double にキャストする必要があります。
double pages = (double)total/(double)perPage;
残りはうまくいくはずです