Inverse percentage

I have a percentage, it ranges from 50% to 0%.

I need values โ€‹โ€‹that need to be mirrored, so:

0% now equals 50%
1% = 49%
25% = 25%
48% = 2%
50% = 0%

and etc.

Thanks for any help!

+3
source share
4 answers

You can use j = max_i - i + min_iwhere the two constants min_i and max_i are the lower and upper limits of the range.

If I am always between 0 and 50, you can simply write j = 50 - i.

+10
source

It looks like you want to define a function like this:

(x)      f(x)
 0        50
 1        49
 2        48
 :         :
48         2
49         1
50         0

Then the function is simple:

f(x) = 50 - x

In the general case, if it xis between lowand highinclusive, then:

f(x) = (high + low) - x

Other features of interest

Here are some other common features:

(x)    f(x)___
 0       0    |
 1       0    3
 2       0 ___|
 3       1    |
 4       1    3     f(x) = x / 3
 5       1 ___|           where / is integer division
 6       2    |
 7       2    3
 :       : ___|

(x)    f(x)___
 0       0    |
 1       1    3
 2       2 ___|
 3       0    |
 4       1    3     f(x) = x % 3
 5       2 ___|           where % is integer remainder
 6       0    |
 7       1    3
 :       : ___|

:

  ______4 columns______
 /                     \
 _______________________     (x)   row(x)   col(x)
|     |     |     |     |     0      0        0
|  0  |  1  |  2  |  3  |     1      0        1
|_____|_____|_____|_____|     2      0        2      row(x) = x / 4
|     |     |     |     |     3      0        3      col(x) = x % 4
|  4  |  5  |  6  |  7  |     4      1        0
|_____|_____|_____|_____|     5      1        1      x = row(x) * 4 + col(x)
|     |     |     |           6      1        2
|  8  |  9  | ... |           7      1        3
|_____|_____|_____|           :      :        :
+14

, pcntAnimationComplt - currImgWidth. , :

pcntAnimationComplt = 50 - Math.round((parseFloat(currImgWidth / pageWidth) * 100) / 2);

It should be from 0 to 50, according to your requirements.

+1
source
var min=1;
var max=50;
for(var i=min;i<=max;i++){document.writeln(i + "<br>");}
for(var i=max;i>=min;i--){document.writeln(i + "<br>");}
0
source

Source: https://habr.com/ru/post/1757124/


All Articles