Posted By

gfazioli on 10/14/08


Tagged

javascript Pad Left zeros padding


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

gfazioli
kayue


Left Pad


 / Published in: JavaScript
 

URL: http://www.undolog.com/2008/10/14/varieta-di-coding-e-di-coding/

Yet another Left padding functions

  1. /**
  2.  * string_pad
  3.  *
  4.  * @author Giovambattista Fazioli
  5.  * @web http://www.undolog.com
  6.  *
  7.  * @param s - String to pad
  8.  * @param l - pad String: Ex "0000" = char "0" len 4
  9.  */
  10. function padding(s,l) { return( l.substr(0, (l.length-s.length) )+s ); }
  11.  
  12. alert( '123','0000' );

Report this snippet  

You need to login to post a comment.