SA-MP Forums Archive
can someone add comma's here for me? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: can someone add comma's here for me? (/showthread.php?tid=640875)



COMMAS in BUSINESS PRICE +REP - BadJih - 08.09.2017

//load 3dtext
if(BizText[idx]) Delete3DTextLabel(BizText[idx]);
if(BizInfo[idx][bOwned] == 0)
{
new pricestring[32];
new price = BizInfo[idx][bValue];
new j = valstr(pricestring,price);
while(j >= 4) { j -= 3; strins(pricestring,",",j); }
strins(pricestring,"$",0);
format(string, sizeof(string), "%s\nStatus: For Sale\nPrice: %s",BizInfo[idx][bName],pricestring);
}
}

i want to change bValue from this (example) : 4000000(4m) to 4,000,000...


Re: can someone add comma's here for me? - SetPlayerNameTag - 08.09.2017

Try create a stock, and using switch to format it if the money is over 1m

for ex: format(string, sizeof(string), "%s", FormatMoney(BizInfo[idx][bValue]));

credits goes to Mariciuc223
Код HTML:
stock FormatMoney(Number)
{
	new str[16];
	format(str, 16, "$%i", Number);
	new l = strlen(str);

	if(Number < 0)
	{
	  	if (l > 5) strins(str, ".", l-3);
		if (l > 8) strins(str, ".", l-6);
		if (l > 11) strins(str, ".", l-9);
	}
	else
	{
		if (l > 4) strins(str, ".", l-3);
		if (l > 7) strins(str, ".", l-6);
		if (l > 10) strins(str, ".", l-9);
	}

	return str;
}



Re: can someone add comma's here for me? - BadJih - 08.09.2017

Quote:
Originally Posted by SetPlayerNameTag
Посмотреть сообщение
Try create a stock, and using switch to format it if the money is over 1m

for ex: format(string, sizeof(string), "%s", bizValue(bid));

credits goes to Mariciuc223
Код HTML:
stock FormatMoney(Number)
{
	new str[16];
	format(str, 16, "$%i", Number);
	new l = strlen(str);

	if(Number < 0)
	{
	  	if (l > 5) strins(str, ".", l-3);
		if (l > 8) strins(str, ".", l-6);
		if (l > 11) strins(str, ".", l-9);
	}
	else
	{
		if (l > 4) strins(str, ".", l-3);
		if (l > 7) strins(str, ".", l-6);
		if (l > 10) strins(str, ".", l-9);
	}

	return str;
}
nno no i need unlimited money because i can set biz price to any price i want 999,9999,999 sometimes... so nobody can buy it


Re: can someone add comma's here for me? - SetPlayerNameTag - 08.09.2017

Quote:
Originally Posted by BadJih
Посмотреть сообщение
nno no i need unlimited money because i can set biz price to any price i want 999,9999,999 sometimes... so nobody can buy it
it also works , the limit is up to 10 billions.


Re: can someone add comma's here for me? - thegamer355 - 08.09.2017

Код:
stock AddComma(numbers) //by Gamer931215
{
	new temp[24],counter = -1;
	valstr(temp,numbers);
	for(new i = strlen(temp);i > 0; i--)
	{
	    counter++;
		if(counter == 3)
		{
		    strins(temp,".",i);
		    counter = 0;
		}
	}
	return temp;
}
use it in this way:

AddComma([value here])
This will add a . every 3 digits (starting from the back)


Re: can someone add comma's here for me? - BadJih - 08.09.2017

Quote:
Originally Posted by SetPlayerNameTag
Посмотреть сообщение
it also works , the limit is up to 10 billions.
ok can you put it on the code i did pasted ??


Re: can someone add comma's here for me? - BadJih - 08.09.2017

Quote:
Originally Posted by SetPlayerNameTag
Посмотреть сообщение
it also works , the limit is up to 10 billions.
check the post again i edited it ! i want to apply that stock for the green line


Re: can someone add comma's here for me? - Vince - 08.09.2017

Quote:
Originally Posted by SetPlayerNameTag
Посмотреть сообщение
Try create a stock, and using switch to format it if the money is over 1m

for ex: format(string, sizeof(string), "%s", FormatMoney(BizInfo[idx][bValue]));

credits goes to Mariciuc223
Код HTML:
stock FormatMoney(Number)
{
	new str[16];
	format(str, 16, "$%i", Number);
	new l = strlen(str);

	if(Number < 0)
	{
	  	if (l > 5) strins(str, ".", l-3);
		if (l > 8) strins(str, ".", l-6);
		if (l > 11) strins(str, ".", l-9);
	}
	else
	{
		if (l > 4) strins(str, ".", l-3);
		if (l > 7) strins(str, ".", l-6);
		if (l > 10) strins(str, ".", l-9);
	}

	return str;
}
This is such a naive approach and it can be written way shorter: https://sampwiki.blast.hk/wiki/AddThousa...ors#Definition

Also the integer limit (for 32 bit signed integers as used by SA-MP) is 2.1 billion and something. It's impossible to store values larger than that.