0
I’m having trouble with a sum in Javascript, example 188/100 = 1.88*100 = 188, but I don’t want it to reach 188, I want the number to always reach 100.
188/100*100 = 100
Guys I got it’s simple!
i = 50;
100/i*i;
0
I’m having trouble with a sum in Javascript, example 188/100 = 1.88*100 = 188, but I don’t want it to reach 188, I want the number to always reach 100.
188/100*100 = 100
Guys I got it’s simple!
i = 50;
100/i*i;
5
If you want a number that multiplied by 188 give 100 as a result, just do:
fator = 100/188; // Perceba que usei 100/188 e não 188/100
cem = fator * 188; // Vai dar 100 (com algum possível problema de arredondamento)
Note: this answer was given before the question was edited, using a complex deductive method (called kick). Anyway, it seems to have solved the OP problem. To see the original question, click here.
Thanks guy I managed to solve the problem
2
Swap a comma for a period. In Javascript, the decimal separator is the point ;)
i and..:
1,88 * 100 // 8800
This is because the interpreter sees it as:
1;
88 * 100;
Already the code below approaches more than you want:
1.88 * 100; // 188;
Another thing. If you want to divide a number into 100 equal parts, continue with this reasoning. If you want a number to reach 100 in exactly 100 addition iterations, then start from 0 and increment to 100. The most classic form, and the first Arcana phrase that most programmers learn, is the following:
for (var i = 0; i < 100; i++)
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Can you explain with other words and more examples what you want? It’s unclear to me.
– Sergio
@Sergio a number 188 times reach the number 100
– Dieguinho Rodrigues
I didn’t understand a thing!
100/i*i == 100
?– utluiz
@utluiz 100/50*50 = 100
– Dieguinho Rodrigues
@I expressed myself badly. What is the purpose of this? It is a basic principle of mathematics that you can "nullify" the same number that is in both the numerator and denominator?
– utluiz
@utluiz I’m doing a function q can send me any number, then I made a pogresso bar up to 100, and I just thought of this alternative.
– Dieguinho Rodrigues
Ahhh!!! So what you want is something thus?
– utluiz
yes, but I’ve already solved
– Dieguinho Rodrigues