[SOLVED] $10000 > $10.000
#1

How can i make a script that change intiger into money notation?
I tryed to make this, but it returns nothing:
pawn Код:
stock inttomoney(money)
{
    new string2[256];
    new string[256];
    format(string,sizeof(string),"%i",money);
    format(string2,sizeof(string2),"%i",money);
    new lang = strlen(string2);
    new totallang = lang+(lang/3);
    new idx=lang;
    for(new i;i<((lang/3)-1);i++)
    { //make space free for points
      new idx2;
      while(idx2 < lang)
      {
            string[idx2-1-(lang/3)] = string2[idx2];
        idx2++;
      }
      string[i] = ' ';
    }
    for(new s=1;s<totallang;)
    {
        s*=3;
        idx = lang-s;
        if((lang-s) < 3)
        {
            for(new i=lang-s;i<s;i--)
            {
                string[idx-i] = string2[idx-i];
            }
            string[idx] = '.';
        } else
        {
            for(new i=3;i<0;i--)
            {
                string[idx-i] = string2[idx-i];
            }
            string[idx] = '.';
        }
    }
    return string;
}
Reply
#2

pawn Код:
CreatePrice( Formatprice )
{
    new
        PriceStr[ 25 ] ,
        formatted[ 25 ];
    format( PriceStr , sizeof( PriceStr ) , "%d" , Formatprice );
    formatted = addCommas( PriceStr );
    return formatted;
}

addCommas( price[ 25 ] )
{
    new
        len = strlen( price );
    if( len <= 3 )
    {
        return price;
    }

    new
        offset = len ,
        returnstr[ 25 ] ,
        tempstr[ 25 ] ,
        dots;

    while( offset >= 3 )
    {
        offset = offset - 3;
        strmid( tempstr , price , offset , ( offset + 3 ) );

        if( dots == 0 )
        {
            returnstr = tempstr;
        }
        else
        {
            format( returnstr , sizeof( returnstr ) , "%s.%s" , tempstr , returnstr );
        }

        dots++;
    }
    if( offset > 0 )
    {
        strmid( tempstr , price , 0 , offset );
        format( returnstr , sizeof( returnstr ) , "%s.%s" , tempstr , returnstr );
    }
    return returnstr;
}
Note that this is not made by me, I got it from someone, can't remember who send it.
Reply
#3

Thank you very mutch
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)