我們在項目開發中少不了要開發報表,而對於數據的處理,用於不少的函數或是方法是必不可少的。其中就包括四捨五入的方法Math.round,這個的用法也是java面試題中常見的。下面是java代碼是Math.round使用方法:
package com.buyli.interview.baseinfo;
/**
* @Copyright @ 2012
* All right reserved
* @version 創建時間:Created on 2012-11-22
* @author 作者:Create by www.360buyli.com
* @Email: [email protected]
* @description java面試題中Math.round的用法
*/
public class RoundInterview {
public static void main(String[] args) {
System.out.println("Math.round(11.5)輸出:"+Math.round(11.5));
System.out.println("Math.round(-11.5)輸出:"+Math.round(-11.5));
}
}
所輸出的結果是:
Math.round(11.5)輸出:12
Math.round(-11.5)輸出:-11