Baruch Mashasha
Baruch Mashasha

Reputation: 979

How to parse string "000" to number in java script

I have string "000" and I want to convert it to a number 000.

parseInt and Number parse it to 0.

I try this:

const number = '0000';
const parseNumber = parseInt(number, 10);
console.log(parseNumber); // the output is 0 :/

thanks :)

Upvotes: 2

Views: 556

Answers (1)

Ar Rakin
Ar Rakin

Reputation: 542

Actually, there is no way to do this because 000 is equivalent to 0! If you want to do some arithmatic operations then simply use 0. If you want to just output 000, then use it as a string.

Upvotes: 2

Related Questions