Hi all,
I have a textbox in Javascript. When I enter '0000.00' in the textbox, I want to know how to convert that to only having one leading zero, such as '0.00'.
Please anybody help me in this regard.
Thanks in advance..
raja.
Hi all,
I have a textbox in Javascript. When I enter '0000.00' in the textbox, I want to know how to convert that to only having one leading zero, such as '0.00'.
Please anybody help me in this regard.
Thanks in advance..
raja.
Try this:
<input type="text" onblur="this.value=this.value.replace(/^0+(?=\d\.)/, '')">
var value= document.getElementById("theTextBoxInQuestion").value;
var number= parseFloat(value).toFixed(2);
It sounds like you just want to remove leading zeros unless there's only one left ("0" for an integer or "0.xxx" for a float, where x can be anything).
How about this for a first cut?
while (s.charAt(0) == '0') {
if (s.length == 1) { break };
if (s.charAt(1) == '.') { break };
s = s.substr(1,s.length-1)
}