SA-MP Forums Archive
How to separate numbers by comma? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to separate numbers by comma? (/showthread.php?tid=259208)



How to separate numbers by comma? - Bloude - 03.06.2011

Hi, if possible, I wish someone would create a function to do so:

pawn Код:
Comma(value);
Where the value would be a number. This function Comma(value) return the string value with the commas.

For example:

pawn Код:
new money, str[110];
money = 1500;
format(str, sizeof(str), "You have %s", Comma(money));
SendClientMessage(playerid, cor, str);
The result would be:

You have 1,500

I appreciate the help.


Re: How to separate numbers by comma? - jameskmonger - 03.06.2011

Slice has already created this.


Re: How to separate numbers by comma? - Bloude - 03.06.2011

Quote:
Originally Posted by jameskmonger
Посмотреть сообщение
Slice has already created this.
You can send me the link of this topic then?

@edit: I find it, thank you James, any moderator, please close this topic.


Re: How to separate numbers by comma? - gamer931215 - 03.06.2011

I made you a function, hopefully this is what you want

pawn Код:
stock Comma(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;
}
Edit: oh did slice ? well anyways this should work as well


Re: How to separate numbers by comma? - jameskmonger - 03.06.2011

You're welcome, enjoy.