Math.round(), Math.floor(),Math.ceil() ,Number.toFixed()
来源:互联网 发布:软件企业即征即退 编辑:程序博客网 时间:2024/06/05 12:01
AS3 数字取整方法
2011 年 03 月 27 日 No Comments
int()去掉小数点
trace(int(3.14)); //输出3
trace(int(-3.14)); //输出-3
Math.round()方法:
Math.round()可以四舍五入对数字取整
trace(Math.round(39.88)); //输出40
trace(Math.round(58.33)); //输出58
Math.floor()方法:
Math.floor()可以向下取整
trace(Math.floor(39.88)); //输出39
trace(Math.floor(58.33)); //输出58
Math.ceil()方法:
Math.ceil()可以向上取整
trace(Math.ceil(39.88)); //输出40
trace(Math.ceil(58.33)); //输出59
toFixed()方法:
toFixed()方法四舍五入取指定位数的小数点,当其中参数为0时表示不留小数点
var temp:Number=3.1415926
//toFixed()中的参数就是需要取的小数位数,0表示不留小数点
var temp:Number=3.1415926
trace(temp.toFixed(2)); //输出3.14
trace(temp.toFixed(0)); //输出3
temp=18.888;
trace(temp.toFixed(0)); //输出19
==============================
Math.round()方法取小数位数:
比如说3.14159要精确到.001位,则先3.14159/.001,然后再Math.round(3.14159/.001),最后在把结果乘以需要精确的位数Math.round(3.14159/.001)*.001
trace(Math.round(3.14159/.001)*.001); //输出3.142
trace(Math.round(3.14159/.01)*.01); //输出3.14
如果不想四舍五入,那直接改round()方法为floor()或者ceil()方法即可
toFixed()方法取小数位数:
直接指定toFixed()中的参数即可,比如要留两位小数,则toFixed(2)
var temp:Number=3.1415926
trace(temp.toFixed(1)); //输出3.1
2011 年 03 月 27 日 No Comments
int()去掉小数点
trace(int(3.14)); //输出3
trace(int(-3.14)); //输出-3
Math.round()方法:
Math.round()可以四舍五入对数字取整
trace(Math.round(39.88)); //输出40
trace(Math.round(58.33)); //输出58
Math.floor()方法:
Math.floor()可以向下取整
trace(Math.floor(39.88)); //输出39
trace(Math.floor(58.33)); //输出58
Math.ceil()方法:
Math.ceil()可以向上取整
trace(Math.ceil(39.88)); //输出40
trace(Math.ceil(58.33)); //输出59
toFixed()方法:
toFixed()方法四舍五入取指定位数的小数点,当其中参数为0时表示不留小数点
var temp:Number=3.1415926
//toFixed()中的参数就是需要取的小数位数,0表示不留小数点
var temp:Number=3.1415926
trace(temp.toFixed(2)); //输出3.14
trace(temp.toFixed(0)); //输出3
temp=18.888;
trace(temp.toFixed(0)); //输出19
==============================
Math.round()方法取小数位数:
比如说3.14159要精确到.001位,则先3.14159/.001,然后再Math.round(3.14159/.001),最后在把结果乘以需要精确的位数Math.round(3.14159/.001)*.001
trace(Math.round(3.14159/.001)*.001); //输出3.142
trace(Math.round(3.14159/.01)*.01); //输出3.14
如果不想四舍五入,那直接改round()方法为floor()或者ceil()方法即可
toFixed()方法取小数位数:
直接指定toFixed()中的参数即可,比如要留两位小数,则toFixed(2)
var temp:Number=3.1415926
trace(temp.toFixed(1)); //输出3.1
- Math.round(), Math.floor(),Math.ceil() ,Number.toFixed()
- Math.round ceil floor
- Math.ceil()和Math.floor()、Math.round()
- Math.round|Math.floor|Math.ceil区别
- Math.floor,Math.round,Math.ceil
- Math.round, Math.ceil 和 Math.floor
- Math.floor()/Math.ceil()/Math.round()
- Math.ceil、Math.floor、Math.round用法
- js Math.abs,ceil,floor,round,toFixed函数的使用
- JS:Math.random(),Math.ceil(),Math.floor()与Math.round()
- Math.random()、Math.ceil()、Math.floor()、Math.round()
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- javascript Math.random(),Math.floor(),Math.ceil(),Math.round()
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- math.random()、math.floor()、math.round()、math.ceil()函数总结
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Ext 页面
- HashMap学习
- 全局变量,局部变量,静态变量,const
- Objective-C的消息传递机制
- Java操作Cookie详解
- Math.round(), Math.floor(),Math.ceil() ,Number.toFixed()
- 高级屏蔽优酷广告(终极利器)
- 制作手札---RPG是怎样做成的 (三)
- iis 7发布的网站,上传大文件时报错
- Is it safe to run a pool under NT AUTHORITY\NETWORK SERVICE?
- GridView的单元格在内容显示超过长度的时候用省略号 ......
- C++ 虚函数,虚函数表
- android 拨打电话 号码判断
- 金融信息交换协议(FIX)v5.0