Taiwo Sulaimon
Taiwo Sulaimon

Reputation: 53

How to change this to a number and keep all digits

"07999323384"

How do I convert the number above to number, but once I use any numeric method it takes out the first zero

Upvotes: 0

Views: 184

Answers (2)

Luke_
Luke_

Reputation: 805

You use Number("07999323384"); except it will take out the first 0, its not possible to have a number beginning with 0 (except the number 0) because js removes leading 0s.

There is nothing you can do about this however that shouldnt matter because there should be no situation where you need it as a number type but also need the first 0

Upvotes: 2

mighty mac
mighty mac

Reputation: 19

Create a copy in a seperate variable to do calculations on (which will drop the leading zero) and use the original variable to maintain the leading zero, it's either that or pad out the number after using your numeric methods presuming it's a fixed length as per this: How can I pad a value with leading zeros?

Upvotes: 1

Related Questions