SA-MP Forums Archive
Float money - 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: Float money (/showthread.php?tid=171671)



Float money - Cameltoe - 27.08.2010

How would i format cash to say like : 1.500.454.435 etc?

I saw on useful functions section a function named NiceMoney, but this didn't work ?

heres the NiceMoney function:

pawn Код:
NiceMoney(amount, sep[] = ".")
{
    new
        money[16],
        negativ = 0;
    if(amount < 0) negativ = 1;
    format(money, sizeof(money), "%i", amount);
    new
        lenght = strlen(money);
    while((lenght -= 3) > negativ) strins(money, sep, lenght);
    return money;
}
Also tested it with a loop:
pawn Код:
new Test[5];
    for(new i; i < sizeof(Test); i++)
    {
        Test[i] = rand(50000,150000);
        printf("%f",NiceMoney(Test[i]));
    }



Re: Float money - Jeffry - 27.08.2010

pawn Код:
stock NiceMoney(amount)
{
    new money[16],negativ = 0, sep[2], tmp; sep= ".";
    if(amount < 0) negativ = 1;
    format(money, sizeof(money), "%d", amount);
    for(new i=strlen(money); i>negativ+1; i--)
    {
        tmp++;
        if(tmp==3) { strins(money, sep, i-1); tmp=0; }
    }
    return money;
}
Usage example:
pawn Код:
printf("%s", NiceMoney(1234567890));
I hope this helps.


Re: Float money - Cameltoe - 27.08.2010

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
pawn Код:
stock NiceMoney(amount)
{
    new money[16],negativ = 0, sep[2], tmp; sep= ".";
    if(amount < 0) negativ = 1;
    format(money, sizeof(money), "%d", amount);
    for(new i=strlen(money); i>negativ+1; i--)
    {
        tmp++;
        if(tmp==3) { strins(money, sep, i-1); tmp=0; }
    }
    return money;
}
Usage example:
pawn Код:
printf("%s", NiceMoney(1234567890));
I hope this helps.
Yeah, let me try ^^


Re: Float money - woot - 27.08.2010

pawn Код:
// number_format function by Slice i think
stock number_format( num )
{
    new stri[16], stro[16], i, v, p, d, l, n = num < 0;
    format( stri, sizeof( stri ), "%d", num * ( n ? -1 : 1 ) );

    l = strlen( stri ) - 1;
    d = ( l - ( l % 3 ) ) / 3;
    l = l + 1;
    i = l + d;
    p = l;
    while ( i >= 0 )
    {
        v = l + d - i;
        if ( v && !( v % 4 ) )
            stro[i + n] = ',';
        else
            stro[i + n] = stri[p--];
        i--;
    }
    stro[0] = n ? '-' : stro[0];
    return stro;
}



Re: Float money - Cameltoe - 27.08.2010

None of them does work :S..

Lol their a string ! not a int.. xD thanks for help!


Re: Float money - Jeffry - 27.08.2010

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
None of them does work :S..
O.o I tested it. :/

Show your code how you use it please.


Re: Float money - Cameltoe - 27.08.2010

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
O.o I tested it. :/

Show your code how you use it please.
Work's now i thought the number's where int's but there were strings lol thanks^^


Re: Float money - Slice - 27.08.2010

Quote:
Originally Posted by exora
Посмотреть сообщение
pawn Код:
// number_format function by Slice i think
stock number_format( num )
{
    new stri[16], stro[16], i, v, p, d, l, n = num < 0;
    format( stri, sizeof( stri ), "%d", num * ( n ? -1 : 1 ) );

    l = strlen( stri ) - 1;
    d = ( l - ( l % 3 ) ) / 3;
    l = l + 1;
    i = l + d;
    p = l;
    while ( i >= 0 )
    {
        v = l + d - i;
        if ( v && !( v % 4 ) )
            stro[i + n] = ',';
        else
            stro[i + n] = stri[p--];
        i--;
    }
    stro[0] = n ? '-' : stro[0];
    return stro;
}
yeah it is lol. haven't seen that in ages, where'd you find it?


Re: Float money - Jeffry - 27.08.2010

Quote:
Originally Posted by Cameltoe
Посмотреть сообщение
Work's now i thought the number's where int's but there were strings lol thanks^^
Great. Thanks for the feedback.

Have fun.