Math Issue
#1

pawn Код:
CMD:rates(playerid, params[])
{

    new string[128];
    format(string, 128, "Interest: %d%s, %d", IntRate, "%%", IntRate/100);
    SendClientMessage(playerid, COLOR_WHITE, string);
    format(string, 128, "Tax: %d%s, %d", TaxRate, "%%", TaxRate/100);
    SendClientMessage(playerid, COLOR_WHITE, string);
   
    return 1;
}
It shows the correct values for both rates, but when I attempt math with them, it returns 0.
Reply
#2

Try use %f format specifier for float values.

For example:
Код:
format(string, 128, "Interest: %d%s, %f", IntRate, "%%", IntRate/100);
Reply
#3

Quote:
Originally Posted by austin070
Посмотреть сообщение
It shows the correct values for both rates, but when I attempt math with them, it returns 0.
Quote:
Originally Posted by terrance
Посмотреть сообщение
Try use %f format specifier for float values.

For example:
Код:
format(string, 128, "Interest: %d%s, %f", IntRate, "%%", IntRate/100);
Exactly, its 0 because 5/100 as a floating point operation is 0.05, but as an integer operation 0.05 its not valid, so it will be just 0, like 5/2 its 2.

Follow what Terrance said.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)