提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用java.lang.Math round()方法对数字进行四舍五入。
public class Main { public static void main(String[] args){ // Round a float value to an Integer//from NowJava.com - 时代Java System.out.println(roundFloatToInt(new Float("8.837"))); System.out.println(roundDoubleToLong(new Double("9.9"))); } /** * Rounds a floating-point number to an Integer and returns the result * @param myFloat * @return */ public static int roundFloatToInt(float myFloat){ return Math.round(myFloat); } /** * Rounds a Double value to an Integer and returns the result * @param myDouble * @return */ public