您的位置:首页 > Web前端 > JavaScript

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: