Flex Nunber 四舍五入取值
来源:互联网 发布:Windows 系统 编辑:程序博客网 时间:2024/05/16 06:04
转自:http://www.cnblogs.com/Anlycp/archive/2011/12/07/2279401.html
查了很多四舍五入的取值方式,悲剧了 都只介绍toFixed,但取得值好像不是四舍五入。怎么大家就没想过用round来求得呢,round取得的是整数进行四舍五入
下面例子是取两位小数,如果取三位小数,值需要改为Math.round(a*1000)/1000 ,以此类推。。。
var a:Number=new Number();
a=1.1456
//保留两位小数,并且四舍五入
a=Math.round(a*100)/100 //a 值为1.15
a=1.1456
//保留两位小数,不进行四舍五入
var b:String=currencyFormatter.format(a); //a 值为1.14
//toFixed 取两位小数的时候 是四舍五入;取一、三位小数的时候是五舍六入 好邪门,不大会用
a=1.14
a=Number(a.toFixed(1)); //a 值为1.1
a=1.154
a=Number(a.toFixed(2)); //a 值为1.15
a=1.1554
a=Number(a.toFixed(3)); //a 值为1.155
a=1.15
a=Number(a.toFixed(1)); //a 值为1.1
a=1.155
a=Number(a.toFixed(2)); //a 值为1.16
a=1.1555
a=Number(a.toFixed(3)); //a 值为1.155
a=1.16
a=Number(a.toFixed(1)); //a 值为1.2
a=1.156
a=Number(a.toFixed(2)); //a 值为1.16
a=1.1556
a=Number(a.toFixed(3)); //a 值为1.156
a=1.1456
//保留两位小数,并且四舍五入
a=Math.round(a*100)/100 //a 值为1.15
a=1.1456
//保留两位小数,不进行四舍五入
var b:String=currencyFormatter.format(a); //a 值为1.14
//toFixed 取两位小数的时候 是四舍五入;取一、三位小数的时候是五舍六入 好邪门,不大会用
a=1.14
a=Number(a.toFixed(1)); //a 值为1.1
a=1.154
a=Number(a.toFixed(2)); //a 值为1.15
a=1.1554
a=Number(a.toFixed(3)); //a 值为1.155
a=1.15
a=Number(a.toFixed(1)); //a 值为1.1
a=1.155
a=Number(a.toFixed(2)); //a 值为1.16
a=1.1555
a=Number(a.toFixed(3)); //a 值为1.155
a=1.16
a=Number(a.toFixed(1)); //a 值为1.2
a=1.156
a=Number(a.toFixed(2)); //a 值为1.16
a=1.1556
a=Number(a.toFixed(3)); //a 值为1.156
定义下currencyFormatter 为两位小数,同时去除货币符号
<fx:Declarations>
<mx:CurrencyFormatter id="currencyFormatter" currencySymbol="" precision="2" />
</fx:Declarations>
<mx:CurrencyFormatter id="currencyFormatter" currencySymbol="" precision="2" />
</fx:Declarations>
- Flex Nunber 四舍五入取值
- double取值四舍五入
- Math对象 四舍五入取值
- javascript对小数四舍五入取值?
- flex属性取值
- flex小数点四舍五入
- js取整数四舍五入
- 关于取整 四舍五入
- js取整数四舍五入
- java 四舍五入取整
- java 四舍五入取整
- js取整数四舍五入
- C++ 取整,四舍五入
- 小数取整 四舍五入
- double 取 四舍五入
- js取整数四舍五入
- Flex——四舍五入函数
- java取四舍五入的方法
- 面试题:从无头链表中删除已知结点
- 将java工程转为web工程
- Ubuntu自动挂载NTFS分区
- 查看当前运行的所有任务 【tasklist】
- Problem E Codeforces Round #184 (Div. 2) B. Continued Fractions
- Flex Nunber 四舍五入取值
- AIX6.1.0.0安装oracle10g
- 浅谈C#中的枚举
- firefox centos flash 插件安装
- web.xml配置详解
- Win 8换徽标全面整合亮点功能大阅兵——乡巴佬下载
- linux:vi 替换命令
- MYSQL数据库自动压缩备份脚本
- ZOJ 3613 Wormhole Transport