08.01.2010, 16:02
IntToFormattedStr(integer):[*] Returns a formatted string adding commas to sepparate every 3 digits. (For example, 1000 will return "1,000", 53426244, will return "53,426,244", and 245 will return "245".
PS: Performance can be improved.
*edit 11 april 2010:
Fixed a problem with negative integers.
pawn Код:
stock IntToFormattedStr(integer)
{
// By Zamaroht
new value[20], string[20];
valstr(value, integer);
new charcount;
for(new i = strlen(value); i >= 0; i --)
{
format(string, sizeof(string), "%c%s", value[i], string);
if(charcount == 3)
{
if((integer >= 0 && i != 0) || (integer < 0 && i > 1))
format(string, sizeof(string), ",%s", string);
charcount = 0;
}
charcount ++;
}
return string;
}
*edit 11 april 2010:
Fixed a problem with negative integers.