How can I convert a string to number without loosing the trailing zeroes
var string1 = '02';
Number(string1); // == 2 - Default output
Number(string1); // == 02 - My requirement
The reason why I want this is: I am passing a date as value to the date HTML element. And the format is yyyy-MM-dd
, month and date format is two digits and if I convert the date (string in my case) to number the leading zeroes are being removed.