Javascript function to display 2 digit number

Hi, Today i am going to share how to display 2 digit number in javascript and jQuery,

Javascript:
-------------
function twodigit(num) {
         var num1 = parseInt(num, 10);
          return num1 < 10 ? "0" + num1 : num1;
    }


JQuery:
---------
$('#count').text(function(i,num) {
  var num1 = parseInt(num, 10);
  return num1 < 10 ? "0" + num1 : num1;
});


Output:
----------
twodigit(1); // returns 01
twodigit(2); // returns 02

Comments

Popular posts from this blog

Ghostscript Installation and Configuration in Windows 7

Joomla - Get user id