+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 15 of 15

Thread: Padding with zeros

  1. #11
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Could you post the whole function you have now?

    Another cup of tea and I should be awake enough to have a look through it....

  2. #12
    Barn Enthusiast guddu is on a distinguished road guddu's Avatar
    Join Date
    Jul 2008
    Location
    Oxford UK
    Posts
    471
    Rep Power
    4

    Code:
    function msPadNumber(vvNumber, vlLength, vlDPs)
    		{
    			var sNumber = '';
    			var neg = false;
    			
    			try
    			{
    				sNumber = vvNumber(0).text;
    			}
    			catch(e)
    			{
    				sNumber = vvNumber.toString();
    			}
    			
    			
    			if(sNumber.search(/-/)!=-1)
    			{
    				sNumber = sNumber.replace(/-/,'');
    				neg=true;
    			}		
    
    			
    			if(sNumber.indexOf('.') != -1)
    			{
    				var lDPs = sNumber.length - sNumber.indexOf('.') - 1;
    				
    				if(lDPs > vlDPs)
    				{
    					sNumber = sNumber.substr(0, sNumber.length + vlDPs - lDPs);
    					vlDPs = 0;
    				}
    				else
    				{
    					vlDPs -= lDPs;
    				} 
    			}
    			
    			for(var i=0; i<vlDPs; i++)
    			{
    				sNumber += '0';
    			}
    			
    			sNumber = sNumber.replace('.','');
    			
    			while(sNumber.length < vlLength)
    			{
    				sNumber = '0' + sNumber;
    			}
    			
    			if(neg) 
    			{	
    									
    				sNumber = '-' + sNumber ;
    			}
    			return sNumber.substr(0, vlLength);
    				
    		}
    
    Love is physical attraction and mental destruction

  3. #13
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I got this to work for me:-
    Code:
    function msPadNumber(vvNumber, vlLength, vlDPs)
      {
       var sNumber = '';
       var neg = false;
       
       try
       {
        sNumber = vvNumber(0).text;
       }
       catch(e)
       {
        sNumber = vvNumber.toString();
       }
       
       
       if(sNumber.search(/-/)!=-1)
       {
        sNumber = sNumber.replace(/-/,'');
        neg=true;
       }  
       
       if(sNumber.indexOf('.') != -1)
       {
        var lDPs;
        if(neg) {
         lDPs = sNumber.length - sNumber.indexOf('.') - 2;
        }else{
         lDPs = sNumber.length - sNumber.indexOf('.') - 1;
        }    
        if(lDPs > vlDPs)
        {
         sNumber = sNumber.substr(0, sNumber.length + vlDPs - lDPs);
         vlDPs = 0;
        }
        else
        {
         vlDPs -= lDPs;
        } 
       }
       
       for(var i=0; i<vlDPs; i++)
       {
        sNumber += '0';
       }
       
       sNumber = sNumber.replace('.','');
       
       while(sNumber.length < vlLength)
       {
        sNumber = '0' + sNumber;
       }
       
       if(neg) 
       { 
             
        sNumber = '-' + sNumber ;
       }
       return sNumber.substr(0, vlLength);
        
      }
    

  4. #14
    Barn Enthusiast guddu is on a distinguished road guddu's Avatar
    Join Date
    Jul 2008
    Location
    Oxford UK
    Posts
    471
    Rep Power
    4

    it seems working.Thanks a lot.
    Love is physical attraction and mental destruction

  5. #15
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by guddu View Post
    it seems working.Thanks a lot.
    I wasn't sure if it was dropping a 0 off the front if it's negative or if that was right...

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO