return_percent.txt
snippets · 668 B · 2010-03-30
return_percent: a tiny function that returns percentages of values.
Download « Back to the snippets list
Hello, this is a really simple thing that I have been using for a long time now to return percents of values and I thought I would share it with anyone else who might find it useful.
Use it as you wish, and have fun!
int return_percent(int current,int total)
{
int final;
final = 100 * current/total;
return final;
}
To add it globally, add this line to merc.h:
int return_percent(int current,int total);
An example of its use would be:
In (do_group), I return values as percents.
int hp_percent;
hp_percent = return_percent(gch->hit,gch->max_hit);
I think that's it, if there is something I missed or its wrong, please let me know :).