I have a problem in a sum in JavaScript, example 188/100 = 1.88 * 100 = 188, but I do not want it to reach 188, I want the number to always reach number 100.
188/100 * 100 = 100
Personally I've got it simple!
i = 50;
100/i*i;
I have a problem in a sum in JavaScript, example 188/100 = 1.88 * 100 = 188, but I do not want it to reach 188, I want the number to always reach number 100.
188/100 * 100 = 100
Personally I've got it simple!
i = 50;
100/i*i;
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 editing the question, using a complex deductive method (called a kick). Anyway, it seems to have solved the PO problem. To see the original question, click here .
Change the comma by period. In Javascript, the decimal separator is the dot;)
i.e.:
1,88 * 100 // 8800
This is because the interpreter sees this as:
1;
88 * 100;
The code below is getting closer than you want:
1.88 * 100; // 188;
Another thing. If you want to divide a number into 100 equal parts, continue with that reasoning. If you want a number to reach 100 in exactly 100 addition iterations, then start from 0 and increase until you reach 100. The most classic form, and the first arcane phrase that most programmers learn, is the following: / p>
for (var i = 0; i < 100; i++)