Java Math.round() 四舍五入方法简介说明
下文笔者将通过示例的方式讲述Math.round方法的功能简介说明,如下所示:
Math.round()方法的功能: 返回一个最接近参数值的数(int,long值) Math.round()语法: long round(double d) int round(float f) 分别用于返回一个最接近的int或long值例:
package com.java265.other;
public class Test {
public static void main(String[] args) throws Exception {
double d = 88.524;
double e = 88.500;
float f = 88;
float g = 10f;
System.out.println(Math.round(d));
System.out.println(Math.round(e));
System.out.println(Math.round(f));
System.out.println(Math.round(g));
}
}
-------运行以上代码,将输出以下信息----
89
89
88
10
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


