SA-MP Forums Archive
Number Check - 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: Number Check (/showthread.php?tid=313985)



Number Check - zxc1 - 28.01.2012

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 !


Re: Number Check - iJumbo - 28.01.2012

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;
}



Re: Number Check - T0pAz - 28.01.2012

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.


Re: Number Check - MP2 - 28.01.2012

https://sampwiki.blast.hk/wiki/AddCommas


Re: Number Check - zxc1 - 28.01.2012

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