A mathematical function to round?
#1

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!");
        }
Reply
#2

PVar[i][BankSavings] += floatround(floatmul(float(PVar[i][BankSavings]), 0.3), floatround_floor);
Reply
#3

You are looking for floatround.

pawn Код:
new Float:F = 55.60;
printf("%d", floatround(F, floatround_round));
// will print 56
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)