I have
var x = "0100";
parseInt(x); // returns 100;
Is there a way I can retain the leading 0s and yet convert to number in Javascript
No.
Numbers don't have leading zeroes; that's a display issue, not a matter of a number's internal representation.
To display the number with leading zeroes, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With