Javascript reaching number 100

Asked

Viewed 246 times

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;
  • Can you explain with other words and more examples what you want? It’s unclear to me.

  • @Sergio a number 188 times reach the number 100

  • I didn’t understand a thing! 100/i*i == 100?

  • @utluiz 100/50*50 = 100

  • 1

    @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 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.

  • Ahhh!!! So what you want is something thus?

  • yes, but I’ve already solved

Show 3 more comments

2 answers

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.

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

You are not signed in. Login or sign up in order to post.