Sometimes developer gets the unformated numbers from the server as a result but they have to show the formated data on the screen according to their choice.Below is a very good example which will remove the leading zeros from the number. Make sure the number you have will be string otherwise ithing will not work.That is the only reason below code snippet has value=value.toString(); line which is converting the number into string.
<html>
<script>
function RemoveLeadingZero(value)
{
value=value.toString();
while (value.charAt(0)=="0")
{
value=value.substring(1,value.length);
}
if (value.charAt(0)==".")
{
value="0"+value;
}
return(value);
}
var z="00000000.5000";
alert(RemoveLeadingZero(z));
</script>
</html>
Friday, August 24, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment