28.12.2009, 07:53
I explain: i've a bank system and i like to make it better for readble side.
I dont wanna to see "You have $12852687" in your bank account, but i wanna see "You have $12.852.687" so i tried to make a funcion that returns a string with the money with dots.
I think the way to to that, that i've done, its correct but for some strange reasons it returns '0' in a point and... i dont find a sense... why it returns 0?
Here is my code i hope someone can help.. thx guys.
if they are some stupd errors pls tell me..
I dont wanna to see "You have $12852687" in your bank account, but i wanna see "You have $12.852.687" so i tried to make a funcion that returns a string with the money with dots.
I think the way to to that, that i've done, its correct but for some strange reasons it returns '0' in a point and... i dont find a sense... why it returns 0?
Here is my code i hope someone can help.. thx guys.
Код:
FormatMoney(money)
{
new str[256], str2[256];
new dot = 0, dots = 0, var;
if(money < 1000) return str; //if money have no dots then return immediatly
else if(money >= 1000 && money <= 999999) var = 1; // var is tha dot, if the number is in that interval then it has 1 dot
else if(money >= 1000000) var = 2; // 2 dots if it is bigger than 1 mill
for(new i = sizeof(str); i >= 0; i--)
{
if(dot == 3)//we go here if 3 numbers have been transferred so we write the dot
{
dot = 0;
str2[i + var] = '.';
i--;
dots++;
if((dots == 1 && var == 1) || (dots == 2 && var == 2)) break;
}
else //we go here if 3 numbers have not been passed
{
str2[i + var] = str[i]; // here comes the return 0, ive seen it making a debug with the print() func.
dot++;
}
}
str = "";
format(str, 256, "%s", str2);
return str;
}
// then if the func is correct i use it like this:
new string[256];
string = FormatMoney(PlayerMoney[playerid]);


