5D艺术网首页
商城
|
资讯
|
作品
|
博客
|
教程
|
论坛
登录
注册
加为好友
发短消息
来自:
性别:秘密
最后登录:2009-03-18
http://jybbh.5d.cn/
首页
|
新闻
|
话题
|
博客
|
相册
|
艺术作品
|
社交关系
|
留言板
|
社交圈
2005/05/17 | JS四舍五入
类别(WEB相关)
|
评论
(0)
|
阅读(167)
|
发表于 13:18
a=3.45
b=5.21
a=Math.ceil(a)
b=Math.floor(b)
转化后得a=4 b=5
public class CeilAndFloor {
public static void main(String[] args) {
/*
这两个宝贝函数的主要任务是截掉小数以后的位数.
区别是: floor总是把数字变得越来越小,而ceil总是把数字变大。
其实名字可以理解floor是地板,ceil是天花板。
*/
System.out.println("==============Math.floor()==============");
System.out.println("Math.floor(99.1) = " + Math.floor(99.1));
System.out.println("Math.floor(-99.1) = " + Math.floor(-99.1));
System.out.println("Math.floor(99.9) = " + Math.floor(99.9));
System.out.println("Math.floor(-99.9) = " + Math.floor(-99.9));
System.out.println("\n\n==============Math.ceil()==============");
System.out.println("Math.ceil(99.1) = " + Math.ceil(99.1));
System.out.println("Math.ceil(-99.1) = " + Math.ceil(-99.1));
System.out.println("Math.ceil(99.9) = " + Math.ceil(99.9));
System.out.println("Math.ceil(-99.9) = " + Math.ceil(-99.9));
}
}
结果
==============Math.floor()==============
Math.floor(99.1) = 99.0
Math.floor(-99.1) = -100.0
Math.floor(99.9) = 99.0
Math.floor(-99.9) = -100.0
==============Math.ceil()==============
Math.ceil(99.1) = 100.0
Math.ceil(-99.1) = -99.0
Math.ceil(99.9) = 100.0
Math.ceil(-99.9) = -99.0
0
评论
Comments
日志分类
首页
[252]
Ken的日志
[63]
工作心得
[3]
编程相关
[28]
潮汕文化
[4]
计算机相关
[28]
WEB相关
[84]
JAVA相关
[20]
Eclipse相关
[7]
Tomcat相关
[1]
SQL
[14]