通过最近的学习,学到了一些的Math类中的常见方法

package org.stm.demo;

public class Test {

public static void main(String[] args) {

    /**
* Math.abs(绝对值)
*/
System.out.println(Math.abs(-11.8)); //11.8
System.out.println(Math.abs(-0.0)); //0.0
/**
* Math.ceil(天花板)
*/
System.out.println(Math.ceil(-11.8)); //-11.0
System.out.println(Math.ceil(10.8)); //11.0
System.out.println(Math.ceil(-0.6)); //-0.0
System.out.println(Math.ceil(0.0)); //0.0
System.out.println(Math.ceil(-0.0)); //-0.0 /**
* Math.floor(地板)
*/
System.out.println(Math.floor(-11.1)); //-12.0
System.out.println(Math.floor(11.7)); //11.0
System.out.println(Math.floor(-0.7)); //-1.0
System.out.println(Math.floor(0.0)); //0.0
System.out.println(Math.floor(-0.0)); //-0.0 /**
* Math.max(arg0,arg1)
* Math.min(arg0,arg1)
*/
System.out.println(Math.max(-11.1, -11)); //-11.0
System.out.println(Math.max(11.7, 11)); //11.7
System.out.println(Math.max(0.0, -0.0)); //0.0 /**
* round 四舍五入,float时返回int值,double时返回long值
* Math.round(x) = Math.floor(x+0.5)
*/
System.out.println(Math.round(10.1)); //10
System.out.println(Math.round(10.7)); //11
System.out.println(Math.round(10.5)); //11
System.out.println(Math.round(10.51)); //11
System.out.println(Math.round(-10.5)); //-10
System.out.println(Math.round(-10.51)); //-11
System.out.println(Math.round(-10.6)); //-11
System.out.println(Math.round(-10.2)); //-10 /**
* rint 四舍五入,返回double值
* 注意.5的时候会取偶数
*/
System.out.println(Math.rint(10.1)); //10.0
System.out.println(Math.rint(10.7)); //11.0
System.out.println(Math.rint(11.5)); //12.0
System.out.println(Math.rint(10.5)); //10.0
System.out.println(Math.rint(10.51)); //11.0
System.out.println(Math.rint(-10.5)); //-10.0
System.out.println(Math.rint(-11.5)); //-12.0
System.out.println(Math.rint(-10.51)); //-11.0
System.out.println(Math.rint(-10.6)); //-11.0
System.out.println(Math.rint(-10.2)); //-10.0
}

}

如果大家有疑问,可评论,也可以到APl中查到相应的用法以及到编辑器里面不妨一试!加油>>>

在java中浅谈Math类中的常用方法的更多相关文章

  1. Math类中的BigDecimal

    如果我们编译运行下面这个程序会看到什么? public class Test {    public static void main(String args[]) {                 ...

  2. 转:浅谈C/C++中的指针和数组(一)

    再次读的时候实践了一下代码,结果和原文不一致 error C2372: 'p' : redefinition; different types of indirection 不同类型的间接寻址 /// ...

  3. 转载 浅谈C/C++中的static和extern关键字

    浅谈C/C++中的static和extern关键字 2011-04-21 16:57 海子 博客园 字号:T | T   static是C++中常用的修饰符,它被用来控制变量的存贮方式和可见性.ext ...

  4. Math类中round、ceil和floor方法的功能

    Java中的Math工具类用来完成除+.-.*./.%等基本运算以外的复杂运算,位于java.lang包下,Math类的构造器全是私有的(private),因此无法创建Math类的对象,Math类的方 ...

  5. 浅谈关于QT中Webkit内核浏览器

    关于QT中Webkit内核浏览器是本文要介绍的内容,主要是来学习QT中webkit中浏览器的使用.提起WebKit,大家自然而然地想到浏览器.作为浏览器内部的主要构件,WebKit的主要工作是渲染.给 ...

  6. 浅谈 Swift 2 中的 Objective-C 指针

    浅谈 Swift 2 中的 Objective-C 指针 2015-09-07  499 文章目录 1. 在 Swift 中读 C 指针 2. 在 Swift 中创建 C 指针 3. 总结 作者:Ja ...

  7. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程

    c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...

  8. 你真的懂Flask中浅谈蓝图Blueprint吗?

    一,什么是Flask中的蓝图Blueprint Blueprint是用于实现Flask框架中单个应用的视图,模板,静态文件的集合. Blueprint 是一个存储操作(路由映射)方法的容器,这些操作在 ...

  9. 浅谈人脸识别中的loss 损失函数

    浅谈人脸识别中的loss 损失函数 2019-04-17 17:57:33 liguiyuan112 阅读数 641更多 分类专栏: AI 人脸识别   版权声明:本文为博主原创文章,遵循CC 4.0 ...

随机推荐

  1. 【网址】ILSpy,C# .net/dot net的反编译工具

    ILSpy官网:http://ilspy.net/ ILSpy中文版:http://www.fishlee.net/soft/ilspy_chs/

  2. java.lang.NumberFormatException错误及解决方法

    java.lang.NumberFormatException 一般由Integer.valueOf(String param)或者Integer.parseInt(String param)引起 不 ...

  3. sql server error 53

    主要是计算机名修改了,通过服务器名称,浏览更多,选择“数据库引擎”里面的第一个,就可以登陆了

  4. [转] jquery作者John Resig编写的微模板引擎:JavaScript Micro-Templating

    I've had a little utility that I've been kicking around for some time now that I've found to be quit ...

  5. 【C语言】数组知识点总结

    [C语言]数组知识点总结 标签: 数组 2018年04月12日 17:44:4481人阅读 评论(0) 收藏 举报  分类: C语言知识总结(4)  版权声明:本文为博主原创文章,未经博主允许不得转载 ...

  6. Android最火热修复实战

    Sophix官网文档地址 https://help.aliyun.com/document_detail/53240.html 快速接入 项目build.gradle的repositories节点下添 ...

  7. [Codeforces178F2]Representative Sampling

    Problem 给定n个字符串Si,任意选出k个字符串Ai,使得其中任意两个字符串lcp之和最大. Solution 建一棵trie树,枚举每一个节点对答案的贡献,树形dp,时间复杂度像是O(N^3) ...

  8. Vue学习Day003

    事件修饰符 在事件处理程序中调用 event.preventDefault() 或 event.stopPropagation() 是非常常见的需求.尽管我们可以在方法中轻松实现这点,但更好的方式是: ...

  9. spring整合redis(哨兵模式)

    首先服务器搭建哨兵模式(我这里使用的是Windows8系统),感谢两位博主,少走不少弯路,在此给出链接:服务器哨兵模式搭建和整合哨兵模式 什么一些介绍就不介绍了,可以看一下连接,比较详细,初次接触,当 ...

  10. union、union all 、distinct的区别和用途

    1.从用途上讲 它们都具有去重的效果 2.从效率上讲 distinct通常不建议使用,效率较低;union all 和union 而言,union all效率更高;原因是:union 相当于多表查询出 ...