AmazingDayToday
AmazingDayToday

Reputation: 4272

How to concatenate zeros to a number?

This is the number:

555

I want to make it:

555000

How to do that?

This didn't work:

"" + 555 + 000

Upvotes: 0

Views: 205

Answers (4)

Mendi Sterenfeld
Mendi Sterenfeld

Reputation: 397

Make it to string then to number :

let x = 555;
x +='000'
let y = Number(x)

Or just do the math

let x=555*1000

Upvotes: 2

Jack Bashford
Jack Bashford

Reputation: 44125

Just create a string and parse to a number:

var n = +`${555}000`;

console.log(n);

Upvotes: 1

Chris Dąbrowski
Chris Dąbrowski

Reputation: 1992

It's 2019 :)

console.log(`${555}000`);

Though I really encourage not to mix types.

Upvotes: 2

Fucazu
Fucazu

Reputation: 988

This works:

let x = Number(555 + '000')

Try yourself.

Upvotes: 3

Related Questions