How to convert 1,2,3 to 01,02,03 in java script.

Posted by Allemahesh under JavaScript on 7/15/2013 | Points: 10 | Views : 4111 | Status : [Member] [MVP] | Replies : 3
I want to convert 1,2,3,4,5,6,7,8,9 to 01,02,03,04,05,06,07,08,09 in JavaScript. Can any one help me.




Responses

Posted by: Prtkaggrwl on: 7/15/2013 [Member] Starter | Points: 25

Up
0
Down
<script>
function fnc()
{
var x = 1;
var y = "0"+x;
alert(y);
}
</script>

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 7/15/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Thanks for you answer. But if the x = 10, then any value will be 010. It is wrong. The current value is 10. So can you help me.

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 7/15/2013 [Member] Starter | Points: 25

Up
0
Down
var Value= 1;
var minLength = "00";
label1.Text=minLength.Substring(0, minLength.Length - Value.Length) + Value;

or

var Value= 1;
label1.Text = Value.ToString("D2");

Regards,
Jayakumar Selvakani

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response