本文介紹了四舍五入將其轉換為 int (java)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
現在我正在嘗試這個:
int a = round(n);
其中 n
是 double
但它不起作用.我究竟做錯了什么?
where n
is a double
but it's not working. What am I doing wrong?
推薦答案
片段中round()
方法的返回類型是什么?
What is the return type of the round()
method in the snippet?
如果這是 Math.round()
方法,當輸入參數為 Double 時,它??會返回 Long.
If this is the Math.round()
method, it returns a Long when the input param is Double.
所以,你將不得不轉換返回值:
So, you will have to cast the return value:
int a = (int) Math.round(doubleVar);
這篇關于四舍五入將其轉換為 int (java)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!