Java floor() 方法

Java 教程 · 2019-02-08 11:57:13

floor() 方法可对一个数进行下舍入,返回给定参数最大的整数,该整数小于或等给定的参数。

语法

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

double floor(double d)

double floor(float f)

参数

  • double 或 float 的原生数据类型。

返回值

返回 double 类型数组,小于或等于给定的参数。

实例

public class Test{
    public static void main(String args[]){
        double d = 100.675;
        float f = -90;

        System.out.println(Math.floor(d));
        System.out.println(Math.floor(f));

        System.out.println(Math.ceil(d));
        System.out.println(Math.ceil(f));
    }
}

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

100.0
-90.0
101.0
-90.0

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

查看所有标签

The Practice of Programming

The Practice of Programming

Brian W. Kernighan、Rob Pike / Addison-Wesley / 1999-2-14 / USD 49.99

With the same insight and authority that made their book The Unix Programming Environment a classic, Brian Kernighan and Rob Pike have written The Practice of Programming to help make individual progr......一起来看看 《The Practice of Programming》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具