can someone add comma's here for me?
#1

//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...
Reply
#2

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;
}
Reply
#3

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
Reply
#4

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.
Reply
#5

Код:
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)
Reply
#6

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 ??
Reply
#7

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
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)