newbie27
asked on
function to format a fixed digit number
Hello Folks,
I am using attached function to format some fixed digit number but it is giving me an error.
Please can you see if this is not correct?
thanks
s
I am using attached function to format some fixed digit number but it is giving me an error.
Please can you see if this is not correct?
thanks
s
<script>
function twoDecimal(num,round) {
if (round) return num.toFixed(2);
var stringNum = String(num);
if (stringNum.indexOf('.')==-1) return stringNum+'.00';
var newNum = stringNum.split('.');
if (newNum.len==2) {
newNum[1]=(newNum[1].length>2)?newNum[1].subString(0,2):newNum[1];
}
if (newNum[1].length==1) newnum[1]+="0"
return newNum[0]+'.'+newNum[1]
}
alert(twoDecimal(133.5999,1));
alert(twoDecimal(133.5999));
alert(twoDecimal(133));
alert(twoDecimal(133.5));
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER