Raised This Month: $30 Target: $400
 7% 

Put a comma in a number


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
papel
Junior Member
Join Date: Jul 2017
Old 07-17-2017 , 15:56   Put a comma in a number
Reply With Quote #1

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.

Last edited by papel; 07-17-2017 at 15:57. Reason: Wrong writing
papel is offline
Desktop
AlliedModders Donor
Join Date: Sep 2009
Location: C:\Users\Default\
Old 07-17-2017 , 20:48   Re: Put a comma in a number
Reply With Quote #2

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.
__________________
Massive Infection:: Piu-Games

Last edited by Desktop; 07-17-2017 at 20:51.
Desktop is offline
papel
Junior Member
Join Date: Jul 2017
Old 07-18-2017 , 07:56   Re: Put a comma in a number
Reply With Quote #3

Fantastic. Thanks a lot for the help.
papel is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:26.


Powered by vBulletin®
Copyright ©2000 - 2023, vBulletin Solutions, Inc.
Theme made by Freecode