Java round() 方法

Java 教程 · 2019-02-08 12:28:32

round() 方法返回一个最接近的int、long型值。

语法

该方法有以下几种语法格式:

long round(double d)

int round(float f)

参数

  • d -- double 或 float 的原生数据类型

  • f -- float 原生数据类型

返回值

返回一个最接近的int、long型值,方法会指定返回的数据类型。

实例

实例

public class Test{ public static void main(String args[]){ double d = 100.675; double e = 100.500; float f = 100; float g = 90f; System.out.println(Math.round(d)); System.out.println(Math.round(e)); System.out.println(Math.round(f)); System.out.println(Math.round(g)); } }

编译以上程序,输出结果为:

101
101
100
90

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

The Little Prover

The Little Prover

Daniel P. Friedman、Carl Eastlund / The MIT Press / 2015-7-10 / USD 38.00

[FROM www.amazon.com]: The Little Prover introduces inductive proofs as a way to determine facts about computer programs. It is written in an approachable, engaging style of question-and-answer, wi......一起来看看 《The Little Prover》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

html转js在线工具
html转js在线工具

html转js在线工具