Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

Math in javascript doesnt work the way i expected

Im trying to use this equation to make a progress bar but when ever i try to divide a number with a percent it just gives me a error.


The equation:

/* jshint esversion: 6 */
let progress = (this.assetsComplete*100%)/((this.assets.length - this.exceptionLength)*40);

The only problem is when i do the division it gives an error is there a way to fix it?

i have tried adding extra parentheses but that didn't work.

question from:https://stackoverflow.com/questions/65850621/math-in-javascript-doesnt-work-the-way-i-expected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just take it without some percent calculation.

let progress = this.assetsComplete * 40 / (this.assets.length - this.exceptionLength);

The remainder operator % returns a rest of a dvision of a number by another number.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...