Convert $10000 into $10,000
#1

How to convert like this??

$10000 into $10,000

any function please??

saw on many server like this style
Reply
#2

From the sa-mp wiki, there are plenty of other ones in the useful functions thread. Search
pawn Код:
stock addCommas(number)
{
    new
        tStr[13]; // Up to 9,999,999,999,999
 
    format(tStr,sizeof(tStr),"%d",number);
 
    if(strlen(tStr) < 4)
    return tStr;
 
    new
        //rNumber = floatround((number+(number/3)),floatround_floor),
        iPos = strlen(tStr),
        iCount = 1;
 
    while(iPos > 0)  {
        if(iCount == 4) {
            iCount = 0;
            strins(tStr,",",iPos,1);
            iPos ++;
        }
     
        iCount ++;
        iPos --;
    }
    return tStr;
}
Reply
#3

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
From the sa-mp wiki, there are plenty of other ones in the useful functions thread. Search
pawn Код:
stock addCommas(number)
{
    new
        tStr[13]; // Up to 9,999,999,999,999
 
    format(tStr,sizeof(tStr),"%d",number);
 
    if(strlen(tStr) < 4)
    return tStr;
 
    new
        //rNumber = floatround((number+(number/3)),floatround_floor),
        iPos = strlen(tStr),
        iCount = 1;
 
    while(iPos > 0)  {
        if(iCount == 4) {
            iCount = 0;
            strins(tStr,",",iPos,1);
            iPos ++;
        }
     
        iCount ++;
        iPos --;
    }
    return tStr;
}
Thanks!
Reply
#4

Search "ConvertPrice" in the Useful Functions Topic. You will find an optimized version by RyDeR` which I HIGHLY recommend.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)