# 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?

#### smanches

##### New Member
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:

#### AtomSoft

##### Well-Known Member
you see i knew it was simple heh.... thanks a bunch!!!

#### AtomSoft

##### Well-Known Member
ok i have this now:

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

should return a normal 2-3 digit number right?

#### AtomSoft

##### Well-Known Member
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
3
Views
972
Replies
1
Views
2K
Replies
6
Views
2K
Replies
4
Views
3K
Replies
12
Views
5K