javascript学习笔记(四)Number类型

来源:岁月联盟 编辑:exp 时间:2012-06-01

数字格式化方法toFixed()、toExponential()、toPrecision(),三个方法都四舍五入
toFixed() 方法指定小数位个数
toExponential() 方法 用科学计数法表示数,参数指定小数位个数
toPrecision() 方法自动判断调用toFixed()或toExponential()方法,参数指定所有数的位数


1 var num = 99;
2 alert(toFixed(2));                //99.00
3 alert(toExponential(1));    //9.0e+1
4 alert(toPrecision(1));        //9.0e+1
5 alert(toPrecision(2));        //99
6 alert(toPrecision(3));        //99.0

 


摘自 晴天漫步