Format number in Javascript

 
function  FormatFloat(el)
{
    el 
= el.toString();
    
var nums = el.split('.');
    
var result = FormatInt(nums[0]);
    
if(nums[1!= null && nums[1].length > 0)
    
{
        result 
= result + '.'+nums[1];
    }

    
return result;
}


function  FormatInt(el)
{
    el 
= el.toString();
    
if(el == '' || el.length <= 3)
        
return el;
    
var index = el.length -1;
    
var count = 1//record whether should add a comma
    var result = '';
    
for(;index >=0 ; index--)
    
{
        result 
= el.substr(index,1+ result;
        
if( index > 0 && (count% 3 == 0))
        
{
            result 
= ',' + result;
        }

        count 
++;
    }

    
return result;    
}

你可能感兴趣的:(JavaScript,function,null)