AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Put a comma in a number (https://forums.alliedmods.net/showthread.php?t=299530)

papel 07-17-2017 14:56

Put a comma in a number
 
Hello everybody, How are you?

I would like to know how I make the plugin below read a number greater than or equal to 1000, but produces it with a comma separating thousands (1,000).

Https://forums.alliedmods.net/showthread.php?p=728645

I already tried to contact the developer but he is no longer on the forum.

Desktop 07-17-2017 19:48

Re: Put a comma in a number
 
PHP Code:

stock int AddCommas(int iNumchar[] szOutputint iLen)
{
    
char szTmp[17];
    
int iOutputPosiNumPosiNumLen;
    
iNumLen IntToString(iNumszTmpsizeof(szTmp));
    
    if (
iNumLen <= 3)
    {
        
iOutputPos += strcopy(szOutput[iOutputPos], iLenszTmp);
    }
    else
    {
        while ((
iNumPos iNumLen) && (iOutputPos iLen)) 
        {
            
szOutput[iOutputPos++] = szTmp[iNumPos++];
            
            if ((
iNumLen iNumPos) && !((iNumLen iNumPos) % 3)) 
                
szOutput[iOutputPos++] = ',';
        }
        
szOutput[iOutputPos] = EOS;
    }
    return 
iOutputPos;


Usage: AddCommas(number, buffer, sizeof(buffer));
PrintToChat(client, "Number: %d, Commas: %s", number, buffer);

Don't know if this is what you're looking for, i guessed by the title.

papel 07-18-2017 06:56

Re: Put a comma in a number
 
Fantastic:):). Thanks a lot for the help.


All times are GMT -4. The time now is 02:18.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.