Number Check
#1

Hi,

I need a stock for:
If the number is more then 3 digits it will add a "," (eg. 1,085 -- 9,225 -- 5,356,783)

Thanks !
Reply
#2

pawn Код:
stock FormatMoney(Float:amount, delimiter[2]=",")
{
    #define MAX_MONEY_STRING 16
    new txt[MAX_MONEY_STRING];
    format(txt, MAX_MONEY_STRING, "%d", floatround(amount));
    new l = strlen(txt);
    if (amount < 0) // -
    {
        if (l > 5) strins(txt, delimiter, l-3);
        if (l > 8) strins(txt, delimiter, l-6);
        if (l > 11) strins(txt, delimiter, l-9);
    }
    else
    {
        if (l > 4) strins(txt, delimiter, l-3);
        if (l > 7) strins(txt, delimiter, l-6);
        if (l > 10) strins(txt, delimiter, l-9);
    }
    return txt;
}
Reply
#3

Use conditional statement to check the string length by using strlen then concatenate using strcat.

Edit: The person above me^ gave you the function you were requesting for.
Reply
#4

https://sampwiki.blast.hk/wiki/AddCommas
Reply
#5

It's not working..
It's always writing a number between 50-55.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)