js中小数的处理方法
2015-04-10 13:23
337 查看
Math.floor( ) Math对象的方法--取比当前数值小的最大整数 (下取整)。
Math.ceil( ) Math对象的方法--取比当前数值大的最小整数 (上取整)。
Math.round( ) Math对象的方法--四舍五入。
toFixed( ) Number对象的方法--四舍五入保留n位小数。
parseInt( ) 转换为整数
js实际测试结果:
document.writeln(Math.round(10 / 3)); //3
document.writeln(Math.ceil(10/3)); //4
document.writeln(Math.floor(10/3)); //3
var a = 12.3456
document.writeln(a.toFixed(2)); //12.35
document.writeln(parseInt(21.55)); //21
Math.ceil( ) Math对象的方法--取比当前数值大的最小整数 (上取整)。
Math.round( ) Math对象的方法--四舍五入。
toFixed( ) Number对象的方法--四舍五入保留n位小数。
parseInt( ) 转换为整数
js实际测试结果:
document.writeln(Math.round(10 / 3)); //3
document.writeln(Math.ceil(10/3)); //4
document.writeln(Math.floor(10/3)); //3
var a = 12.3456
document.writeln(a.toFixed(2)); //12.35
document.writeln(parseInt(21.55)); //21
相关文章推荐
- JS 小数的常用处理方法
- js处理小数方法
- js 除法 小数 的处理方法(分页等情况)
- JS中,小数的处理方法
- JS 无法通过W3C验证的处理方法
- JavaScript js 精确、保留小数方法
- JS 无法通过W3C验证的处理方法
- 关于.NET TextBox 前台JS赋值 后台得不到值的处理方法总结
- JavaScript js 精确、保留小数方法
- 小数处理的方法
- jQuery中getScript方法引入外部js文件,乱码处理(自己遇到的问题)
- js 中小数的处理
- JS 常用函数 -----------------慢慢添加(统一ie与ff不同处理方法)
- “Windows脚本宿主”autorun.js的处理方法
- js日期处理方法
- JS一些常用的处理字符串的方法
- 在业务系统中处理小数精度,四舍五入,全舍弃,全进位的方法
- 使用prototype.js的事件处理方法
- 比较简单实用的使用正则三种版本的js去空格处理方法
- 终于搞懂js中cookie的一些处理方法。