Raised This Month: $ Target: $400
 0% 

Add some points on a Integer


Post New Thread Reply   
 
Thread Tools Display Modes
Old 03-11-2010, 21:01
Exolent[jNr]
This message has been deleted by Exolent[jNr]. Reason: Oops.
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2010 , 00:36   Re: Add some points on a Integer
Reply With Quote #2

Here's another

Edit: Code updated to work properly with negative numbers and added FloatAddCommas function.
PHP Code:
new szNum14 ];
AddCommas1234567890 szNum charsmaxszNum ) );
//1,234,567,890

AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum absiNum );
    }
    
    
iNumLen num_to_striNum szTmp charsmaxszTmp ) );

    if ( 
iNumLen <= )
    {
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) ) 
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
        
            if( ( 
iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) ) 
                
szOutputiOutputPos++ ] = ',';
        }
        
        
szOutputiOutputPos ] = EOS;
    }
    
    return 
iOutputPos;

PHP Code:
new szNum32 ];
FloatAddCommas10000000000.0 szNum charsmaxszNum ) );
//10,000,000,000.000000

FloatAddCommasFloat:fNum szOutput[] , iLen )
{
    new 
szTmp32 ] , iOutputPos iNumPos iNumLen bool:bPointReached;
    
    if ( 
fNum 0.0 )
    {
        
szOutputiOutputPos++ ] = '-';
        
fNum floatabsfNum );
    }
    
    
float_to_strfNum szTmp charsmaxszTmp ) );
    
iNumLen strfindszTmp "." );

    if ( 
iNumLen <= )
    {
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmp );
    }
    else
    {    
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) ) 
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
            
            
bPointReached = ( bPointReached || ( szTmpiNumPos ] == '.' ) );
            
            if ( !
bPointReached && ( ( iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) ) )
                
szOutputiOutputPos++ ] = ',';
        }
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmpiNumLen ] );
    }
    
    return 
iOutputPos;

__________________

Last edited by Bugsy; 06-05-2010 at 09:37.
Bugsy is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 03-12-2010 , 19:35   Re: Add some points on a Integer
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Here's another

PHP Code:
new szNum14 ];
AddCommas1234567890 szNum charsmaxszNum ) );
//1,234,567,890

AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp15 ] , iOutputPos iNumPos iNumLen num_to_striNum szTmp charsmaxszTmp ) );
    
    while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) ) 
    {
        
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
    
        if( ( 
iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) ) 
            
szOutputiOutputPos++ ] = ',';
    }
    
    
szOutputiOutputPos ] = EOS;
    
    return 
iOutputPos;

It works too (:, thanks Bugsy.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 03-12-2010 , 11:29   Re: Add some points on a Integer
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
Your code is wrong.
If you put this:
12345
Your code will make this:
123,45
Instead of:
12,345
Did you tested it? I tested it and works fine. In my country we use "." instead of ",". That is the unique difference..
Mxnn is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-12-2010 , 17:10   Re: Add some points on a Integer
Reply With Quote #5

Quote:
Originally Posted by Mxnn View Post
Did you tested it? I tested it and works fine. In my country we use "." instead of ",". That is the unique difference..
My bad. I misread one line.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2010 , 19:32   Re: Add some points on a Integer
Reply With Quote #6

Quote:
Originally Posted by Mxnn View Post
Did you tested it? I tested it and works fine. In my country we use "." instead of ",". That is the unique difference..
I tested your function on 10 numbers, each with incrementing number of digits. A few numbers return incorrectly.

PHP Code:
new Test[] = 
{
    
1,
    
11,
    
111,
    
1111,
    
11111,
    
111111,
    
1111111,
    
11111111,
    
111111111,
    
1111111111

Result:

Code:
1 11 111 11.11 //should be 1.111 11.111 111.111 11.11.111 //should be 1.111.111 11.111.111 111.111.111 11.11.111.111 //should be 1.111.111.111
__________________
Bugsy is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 03-12-2010 , 21:07   Re: Add some points on a Integer
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
I tested your function on 10 numbers, each with incrementing number of digits. A few numbers return incorrectly.

PHP Code:
new Test[] = 
{
    
1,
    
11,
    
111,
    
1111,
    
11111,
    
111111,
    
1111111,
    
11111111,
    
111111111,
    
1111111111

Result:

Code:
1 11 111 11.11 //should be 1.111
11.111 111.111 11.11.111 //should be 1.111.111
11.111.111 111.111.111 11.11.111.111 //should be 1.111.111.111

I tested my code and do it correctly..
Code:
] amx_prueba 1
1
] amx_prueba 11
11
] amx_prueba 111
111
] amx_prueba 1111
1.111
] amx_prueba 11111
11.111
] amx_prueba 111111
111.111
] amx_prueba 1111111
1.111.111
] amx_prueba 11111111
11.111.111
] amx_prueba 111111111
111.111.111
] amx_prueba 1111111111
1.111.111.111
] amx_prueba 11111111111
11.111.111.111
No masters loaded
Using default master
] amx_prueba 111
Took it from CS console.

This is the small code
PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "asd"
#define AUTHOR "Mxnn"
#define VERSION "1.0"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_concmd("amx_prueba""prueba"ADMIN_LEVEL_B"asd")
}

public 
prueba(idlevelcid) {
    if (!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED
    
    
new str[15], strpointed[15], len
    read_argv
(1str14)
    
len=strlen(str)
    new 
c
    
    
for (new i=0;i<len;i++) {
        if (
i!=&& ( (len-i)%3==0) ) {
            
add(strpointed14"."1)
            
c++
            
add(strpointed[i+c], 1str[i], 1)
        }
        else
            
add(strpointed[i+c], 1str[i], 1)
    }
    
    
client_print(idprint_console"%s"strpointed)
    return 
PLUGIN_HANDLED

Mxnn is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 03-12-2010 , 22:00   Re: Add some points on a Integer
Reply With Quote #8

If you do this:
PHP Code:
new number=1111
Points
(numberszOutput
Works perfectly.
The problem is the string "Test", i don't know why but don't works. If you do tat i said the function works perfectly..
Mxnn is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2010 , 22:17   Re: Add some points on a Integer
Reply With Quote #9

Test isn't a string, its an array of numbers. I haven't tested each number individually yet but it makes no sense. There should be no difference whether you provide a number directly or via a variable/array element.
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2010 , 23:22   Re: Add some points on a Integer
Reply With Quote #10

I just tested what you said, I get the same result with all 3 methods: "11.11"

new iTemp = 1111;
Points( iTemp , szOutput );

Points( 1111 , szOutput );

Points( Test[ i ] , szOutput );
__________________
Bugsy is offline
Reply



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 19:49.


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