Math Issue - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Math Issue (
/showthread.php?tid=534249)
Math Issue -
austin070 - 28.08.2014
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.
Re: Math Issue -
terrance - 29.08.2014
Try use
%f format specifier for float values.
For example:
Код:
format(string, 128, "Interest: %d%s, %f", IntRate, "%%", IntRate/100);
Respuesta: Re: Math Issue -
kirk - 29.08.2014
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.