[Help] Showing how much money someone have with dots
#1

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.

Код:
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]);
if they are some stupd errors pls tell me..
Reply
#2

Long long time ago, I made a function.. and the time has come to release it.

pawn Код:
stock DecimalPoint(money)
{
  new str[16];
  if(money >= 0)
  {
    format(str, sizeof(str), "$%d", money);
    if(1000 <= money < 10000) strins(str, ".", 2, sizeof(str));
    else if(10000 <= money < 100000) strins(str, ".", 3, sizeof(str));
    else if(100000 <= money < 1000000) strins(str, ".", 4, sizeof(str));
    else if(1000000 <= money < 10000000) { strins(str, ".", 2, sizeof(str)); strins(str, ".", 6, sizeof(str)); }
    else if(10000000 <= money < 100000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); }
    else if(100000000 <= money < 1000000000) { strins(str, ".", 4, sizeof(str)); strins(str, ".", 8, sizeof(str)); }
    else if(money >= 1000000000) { strins(str, ".", 2, sizeof(str)); strins(str, ".", 6, sizeof(str)); strins(str, ".", 10, sizeof(str)); }
  }
  else
  {
    format(str, sizeof(str), "-$%d", money-(money*2));
    if(-1000 >= money > -10000) strins(str, ".", 3, sizeof(str));
    else if(-10000 >= money > -100000) strins(str, ".", 4, sizeof(str));
    else if(-100000 >= money > -1000000) strins(str, ".", 5, sizeof(str));
    else if(-1000000 >= money > -10000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); }
    else if(-10000000 >= money > -100000000) { strins(str, ".", 4, sizeof(str)); strins(str, ".", 8, sizeof(str)); }
    else if(-100000000 >= money > -1000000000) { strins(str, ".", 5, sizeof(str)); strins(str, ".", 9, sizeof(str)); }
    else if(money <= -1000000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); strins(str, ".", 11, sizeof(str));}
  }
  return str;
}
Usage:
pawn Код:
new str[40];
format(str, sizeof(str), "Your money: %s.", DecimalPoint(GetPlayerMoney(playerid)));
SendClientMessage(playerid, WHITE, str);
(Note: it returns a string, so it must always be %s)

The max string it returns is -$2.147.483.647 (16 cells).
..I made that function real long time ago, when I was a beginner

I would also suggest you to read THIS
Reply
#3

OK Thank you very much, it works

And thanks for that topic i see thing a bit more clear now
Reply
#4

no problem :3 +1 post
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)