/** * This function is to round a number. * numberRound: * roundDigit: */ function roundFun(numberRound,roundDigit) { with(Math){ return round(numberRound*pow(10,roundDigit))/pow(10,roundDigit); } }
/** * This function is to foumat a money. * JK 2004-05-21 * numberRound: */ function formatMoney(numberRound) { var tempValue=roundFun(numberRound,2); if(tempValue%1 ==0) return tempValue+".00"; else if (tempValue*10%1 ==0) return tempValue+"0"; else return tempValue; }
if(typeof(Number.prototype.toFixed)!="function") { Number.prototype.toFixed = function(d) { var s=this+"";if(s.indexOf(".")==-1)s+=".";s+=new Array(d+1).join("0"); if (new RegExp("^((-|\\+)?\\d+(\\.\\d{0,"+ (d+1) +"})?)\\d*$").test(s)) { s="0"+ RegExp.$1, pm=RegExp.$2, a=RegExp.$3.length, b=true; if (a==d+2){a=s.match(/\d/g); if (parseInt(a[a.length-1])>4) { for(var i=a.length-2; i>=0; i--) {a[i] = parseInt(a[i])+1; if(a[i]==10){a[i]=0; b=i!=1;} else break;} } s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2"); }if(b)s=s.substr(1); return (pm+s).replace(/\.$/, "");} return this+""; }; }var a = 1.23456; alert(a.toFixed(2));
<script language=javascript> /** * This function is to round a number. * numberRound: * roundDigit: */ function roundFun(numberRound,roundDigit) { with(Math){ return round(numberRound*pow(10,roundDigit))/pow(10,roundDigit); } }function fixNumber(numberRound,roundDigit) { var tempValue=roundFun(numberRound,roundDigit)+""; if(!(/\./).test(tempValue)) tempValue+="."; var zeroStr="000000000000000000000000"; return tempValue+zeroStr.substr(0,tempValue.lastIndexOf(".")+roundDigit+1-tempValue.length); } var a = 11.00101; alert(fixNumber(a,2));</script>
* This function is to round a number.
* numberRound:
* roundDigit:
*/
function roundFun(numberRound,roundDigit)
{
with(Math){
return round(numberRound*pow(10,roundDigit))/pow(10,roundDigit);
}
}
/**
* This function is to foumat a money.
* JK 2004-05-21
* numberRound:
*/
function formatMoney(numberRound)
{
var tempValue=roundFun(numberRound,2);
if(tempValue%1 ==0) return tempValue+".00";
else if (tempValue*10%1 ==0) return tempValue+"0";
else return tempValue;
}
{
Number.prototype.toFixed = function(d)
{
var s=this+"";if(s.indexOf(".")==-1)s+=".";s+=new Array(d+1).join("0");
if (new RegExp("^((-|\\+)?\\d+(\\.\\d{0,"+ (d+1) +"})?)\\d*$").test(s))
{
s="0"+ RegExp.$1, pm=RegExp.$2, a=RegExp.$3.length, b=true;
if (a==d+2){a=s.match(/\d/g); if (parseInt(a[a.length-1])>4)
{
for(var i=a.length-2; i>=0; i--) {a[i] = parseInt(a[i])+1;
if(a[i]==10){a[i]=0; b=i!=1;} else break;}
}
s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2");
}if(b)s=s.substr(1); return (pm+s).replace(/\.$/, "");} return this+"";
};
}var a = 1.23456;
alert(a.toFixed(2));
<script language=javascript>
/**
* This function is to round a number.
* numberRound:
* roundDigit:
*/
function roundFun(numberRound,roundDigit)
{
with(Math){
return round(numberRound*pow(10,roundDigit))/pow(10,roundDigit);
}
}function fixNumber(numberRound,roundDigit)
{
var tempValue=roundFun(numberRound,roundDigit)+"";
if(!(/\./).test(tempValue)) tempValue+=".";
var zeroStr="000000000000000000000000";
return tempValue+zeroStr.substr(0,tempValue.lastIndexOf(".")+roundDigit+1-tempValue.length);
}
var a = 11.00101;
alert(fixNumber(a,2));</script>