码迷,mamicode.com
首页 > 其他好文 > 详细

??? ??? ??? ??? ???

时间:2015-07-01 13:41:25      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

[?? 1, ????? ??]
var num = 3223.98765;
alert( num.toString().match(/^.*\.\d{2}/) || num );
 
[?? 2, toPrecision? indexOf ??]
var num = 3223.98765;
alert( num.toPrecision(num.toString().indexOf(".")+2) );
 
[?? 3, substring? indexOf ??(?? ??)]
var num = 3223.98765;
alert( (num=num.toString()).substring(0, num.indexOf(‘.‘)+2) )
 
[?? 4, toFixed ??]
<SCRIPT TYPE="TEXT/JAVASCRIPT">
//<![CDATA[
 Number.prototype.toFixedOf = function (n){
  if(!n || typeof n != "number" || n > 12) return NaN;
  var reck = 1;
  for (var i=0; i<n; i++) reck *= 10;
  return parseInt(this * reck)/reck;
 }
  
 var num = 3223.987654321234567890123456789
 alert( num.toFixedOf(5) );
//]]>
</SCRIPT>

 

var num = 3223.98765;
alert( (num = num.toFixed(3).toString()).substring(0, num.length-1) );
 
 
 
* ?? ??? parseInt? ???? ???? ??????.
var num = 3223.98765;
alert( parseInt(num * 100)/100 );
 
* ??? ?? ???? ???? ???? ??? ????.
 

??? ??? ??? ??? ???

标签:

原文地址:http://www.cnblogs.com/jweb/p/4612789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!