Youngin
Youngin

Reputation: 261

How to convert number to width string property? Javascript

I am trying to update the width of a div with a javascript variable but cannot understand how to format it properly.

This way works where you define a fixed percentage.

divider.style.width = '20%';

But I am unable to use a variable like this:

var progress = 40/100;
divider.style.width = progress;

Can anyone point out the proper way to format a float variable into a string that the width property will understand?

Upvotes: 0

Views: 163

Answers (1)

irrelephant
irrelephant

Reputation: 4111

Try:

divider.style.width = (progress * 100) + '%';

Upvotes: 2

Related Questions