Rounding numbers
#5

Quote:
Originally Posted by -Luis
Посмотреть сообщение
Hi, I am planning a bank system for my server and I would like to know how I can make it so when a player goes to withdraw it'll say his balance is, example:
Your balance is $542, today you may withdraw $500.

Is it possible, if so how would it be done?
Convert the number to a string, get the first character (in the 542 example, it would be 5), then get the length of the string (542 example = 3), take 1 from the length (length is now 2) and add that many 0's to the end. Something like:

pawn Код:
stock bankRound(number)
{
     new
          szNumStr[10],
          iLen
     ;
     format(szNumStr, sizeof(szNumStr), "%i", number);
     iLen = strlen(szNumStr);
     format(szNumStr, sizeof(szNumStr), "%s", szNumStr[0]);
     for(new i; i < (iLen - 1); i++) format(szNumStr, sizeof(szNumStr), "%s0", szNumStr);
     return strval(szNumStr);
}
Theres probably a MUCH better way to do this, but if you were to use floatround (example), if it were >=n50 (where n is a preceding integer) it would round UP not down.
Reply


Messages In This Thread
Rounding numbers - by Luis- - 20.11.2011, 15:13
Re: Rounding numbers - by .:Kaos:. - 20.11.2011, 15:15
AW: Rounding numbers - by Babul - 20.11.2011, 15:18
Re: Rounding numbers - by Vince - 20.11.2011, 15:19
Re: Rounding numbers - by Ash. - 20.11.2011, 15:37
Re: Rounding numbers - by AndreT - 20.11.2011, 15:45
Re: Rounding numbers - by Luis- - 20.11.2011, 16:04
Re: Rounding numbers - by Finn - 20.11.2011, 16:13

Forum Jump:


Users browsing this thread: 1 Guest(s)