-6

Suppose,

a=0;

then the result should be 00

a=10
result=10

a=2
result=02

like all values needs to round in 2 decimal point. Note: No need to round the values having more than 2 digits.

Barmar
  • 596,455
  • 48
  • 393
  • 495
Arun Jose
  • 11
  • 2

2 Answers2

0

Are you looking for something like that;

var int = 3;
var intStr = ("0" + int).slice(-2);
Output : 03
lucky
  • 11,548
  • 4
  • 18
  • 35
0

For any number of digits

var temp = 9;
if(temp < 10){
var temp = ("0" + temp).slice(-2);
}

For only two digit simply append zero if it is one digit number :-

var temp = 19;
if(temp < 10){
var temp = "0" + temp;
}
Panther
  • 3,124
  • 9
  • 25
  • 47