Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to format string(numbers) printing in javascript

For example. I want to print numbers from 1 to 20

but I want print 1 as 01 , 2 as 02 and so on ..

like image 506
Bader Avatar asked Aug 20 '26 14:08

Bader


1 Answers

formatNumber = function( num )
{
  if ( num < 10 )
  {
    return "0" + num;
  }
  else
  {
    return "" + num;
  }
}
like image 137
Brett Walker Avatar answered Aug 23 '26 02:08

Brett Walker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!