Skip to content Skip to sidebar Skip to footer

Javascript: Keeping The Leading Zero In A Number

I have this simple function below. I'm passing a number with a leading zero as an argument and the leading zero is getting stripped out of the number. How can I prevent that from o

Solution 1:

How can I prevent that from occurring without passing in the number as a string? Is that possible?

No. Leading zeros are of no significance in the number system / representation JS uses and thus they are not stored in the internal representation of a number.

(or, if you like that better, a number has infinite leading zeros)

Solution 2:

By default you wont get the leading numbers if you are storing it as an int. If you want to get the leading zeros then you need to send it as a string. Else it is not possible

Post a Comment for "Javascript: Keeping The Leading Zero In A Number"