Math.round(11.5)等於()Math.round(-11.5)等於(),math.round-11.5

來源:互聯網
上載者:User

Math.round(11.5)等於()Math.round(-11.5)等於(),math.round-11.5

幾天前去面試,這道簡單的題目竟然做錯了,看來基礎就是慢慢積累的,並不斷使用和複習才會成為高手,如果基礎不是那麼熟練,恐怕在成為高手的路上會困難重重,所以在做項目的間歇時間,偶爾回憶一下最基礎的知識,是一個比較好的投資。

好了,下面介紹的就是Math類中三個與取整有關的方法 :

1、Math.round();//四捨五入

2、Math.ceil();//向上取整

3、Math.floor();//向下取整

代碼展示:

public class TextOne {public static void main(String[] args) {/** * 四捨五入取整 */System.out.println(Math.round(11.5));System.out.println(Math.round(-11.5));/** *向上取整  */System.out.println(Math.ceil(11.5));System.out.println(Math.ceil(-11.5));/** * 向下取整 */System.out.println(Math.floor(11.5));System.out.println(Math.floor(-11.5));}}

運行結果:

12
-11
12.0
-11.0
11.0
-12.0





 


mathround(115)等於多少

Math.round(11.5)==12
Math.round(-11.5)==-11
round方法返回與參數最接近的長整數,參數加1/2後,求其floor
 
Mathround(115)等於多少? Mathround(-115)等於多少

Math.round()是四捨五入的函數,所以Math.round(11.5)是12, Math.round(-11.5)是-11
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.