以前总感觉用javascript,今天找了一下,原来有一个Number对象!这个对象有一些处理数据的方法,最然简单,但是挺好用的!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test001.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
function oncheck(){
var oNumber = new Number(55.55050505);
alert(oNumber.toFixed(3));//显示小数点后3位
}
function oncheck2(){
var oNumber = new Number(55.55050505);
alert(oNumber.toPrecision(3));//显示3个数字
}
function oncheck3(){
var oNumber = new Number(55.55050505);
alert(oNumber.toExponential(2)); //用科学计数法,显示小数点后2位
}
</script>
</head>
<body>
<input type="button" value="check" onclick="oncheck()"/>
<input type="button" value="check2" onclick="oncheck2()"/>
<input type="button" value="check3" onclick="oncheck3()"/>
</body>
</html>
分享到:
评论