31.12.2014, 17:40
currency_format
This function returns a number to it's currency format (as a string).
Code:
delim - An optional parameter, it is the character to be used for separating.
Example:
Output:
This function returns a number to it's currency format (as a string).
Code:
pawn Код:
stock currency_format(number, delim[2] = ",")
{
new
temp_Str[32],
temp_Len = 0;
valstr(temp_Str, number, false);
temp_Len = strlen(temp_Str);
strins(temp_Str, "$", 0, sizeof(temp_Str));
if(temp_Len > 3)
{
for(new i = 3; i< temp_Len; i += 3)
{
strins(temp_Str, delim, temp_Len - i+1, sizeof(temp_Str));
}
}
return temp_Str;
}
Example:
pawn Код:
for(new i = 100; i<= 10000000; i*=10)
{
print(currency_format(i, ",")); //is same as currency_format(i)
}
Код:
$100 $1,000 $10,000 $100,000 $1,000,000 $10,000,000