Showing posts with label format number. Show all posts
Showing posts with label format number. Show all posts
javascript padding/convert number to string with leading zeros
Posted by Raj
Javascript padding/convert number to string with leading zeros
In this tutorial,I will explain how to padding/convert number to a string with leading zeros.
padding in javascript is very easy.we are using javascript to format number with leading zero.
Example:Javascript format number with leading zero
<script language="javascript" type="text/javascript">
var number=10;
var num=Number(number);
num_to_string=num.toString();
if(num_to_string.length==1)
{
num_to_string=0+num_to_string;
}
alert(num_to_string);
</script>
In this tutorial,I will explain how to padding/convert number to a string with leading zeros.
padding in javascript is very easy.we are using javascript to format number with leading zero.
Example:Javascript format number with leading zero
<script language="javascript" type="text/javascript">
var number=10;
var num=Number(number);
num_to_string=num.toString();
if(num_to_string.length==1)
{
num_to_string=0+num_to_string;
}
alert(num_to_string);
</script>