Continue to Site

# percent help

Status
Not open for further replies.

#### AtomSoft

##### Well-Known Member
hey guys this should be simple math but heh havent been to school in so long.

i know percentage for normal usage like 10% of 29 is 2.9 but what happens when 0 isnt the least?

like if i have a number from 20 to 60 how do i do it?

the lest is 20 (which is my 0) the most is 60(which is my 100) how do i calculate what 30 would be in percentage?

Take the difference between MIN and MAX. This is the range you apply the percentage to, then just add back in the MIN figure.

So 50% of 20-60 = 50% of 40 = 20 + 20(min) = 40.

So for your example, 20-60 = 40. 30 / 40 = .75 = 75%

Last edited:
you see i knew it was simple heh.... thanks a bunch!!!

ok i have this now:

Code:
    conPer = ((contrast / 40) * 100);

should return a normal 2-3 digit number right?

i got it heh like this:

Code:
    contrast = 57;
conPer = (((float)contrast-20) / 40) * 100;
conPer2 = (unsigned char)conPer;

Status
Not open for further replies.

Replies
21
Views
13K
Replies
1
Views
2K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
6
Views
2K