Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Math problem - Percentage [SOLVED]
MrBehemoth Offline
Senior Member

Posts: 408
Threads: 19
Joined: Feb 2014
Reputation: 40
#4
RE: Math problem - Percentage

I bet it's not always 0%, I bet it can also be 100%, 200% etc. if x is greater than y. Here's why....Remember what Cthulhu pointed out in the rounding thread?

If you do a calculation with integers, the answer is always going to be an integer.

Floats: 1.0f / 2.0f = 0.5f
Ints: 1 / 2 = 0

Mathematically, it doesn't make sense, but it's to do with how integers are stored and calculated. Basically it just chops off everything after the point.

You need to cast your variables as floats. Try this:

PHP Code: (Select All)
int PercentageXY(int &in xint &in y)
{
    return 
int((float(x)/float(y))*100.0f);


08-30-2014, 02:18 AM
Find


Messages In This Thread
RE: Math problem - Percentage - by Mudbill - 08-30-2014, 01:49 AM
RE: Math problem - Percentage - by MrBehemoth - 08-30-2014, 02:18 AM



Users browsing this thread: 1 Guest(s)