A mathematical function to round? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: A mathematical function to round? (
/showthread.php?tid=256909)
A mathematical function to round? -
Skylar Paul - 22.05.2011
I have a savings account system, and every payday you earn 0.3% interest rate. What happens if it gets a decimal considering money doesn't have cents (in this mode atleast)? Is there a mathematical function to round a number to the nearest whole number in PAWN? If so, what is it, and can you give me an example using this code?
pawn Код:
if(PVar[i][BankSavings] != 0) {
if(PVar[i][BankSavings] != 5000) {
PVar[i][BankSavings] += PVar[i][BankSavings]*0.3; //Here is where I would like to round it.
}
else return SendClientMessage(i, -1, "{55FF00}[Bank]{FFFFFF} You have $5,000 and cannot earn any more! Please withdraw your balance from your savings account!");
}
Re: A mathematical function to round? -
Austin - 22.05.2011
PVar[i][BankSavings] += floatround(floatmul(float(PVar[i][BankSavings]), 0.3), floatround_floor);
Re: A mathematical function to round? -
admantis - 23.05.2011
You are looking for floatround.
pawn Код:
new Float:F = 55.60;
printf("%d", floatround(F, floatround_round));
// will print 56