AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   large numbers, easy comma formula? (https://forums.alliedmods.net/showthread.php?t=128571)

HLM 06-02-2010 15:45

large numbers, easy comma formula?
 
I am now dealing with large numbers, for instance, heres part of my vaultdata

Code:

"STEAM_0:1:23359736" "25352" 1275428793
"STEAM_0:0:26956338" "20203" 1275431316
"STEAM_0:0:2602896" "90" 1275442928
"STEAM_0:0:4195803" "15364" 1275433771
"STEAM_0:0:32292700" "1792" 1275432037
"STEAM_0:0:502059838" "80097" 1275433771
"STEAM_0:0:3617883" "30" 1275433598
"STEAM_0:1:10310702" "201246" 1275440328

middle column are the numbers im dealing with, as you can see, some are low, and some are high (highest on record was over 1 billion, we found out it will loop down into the negatives, im assuming that could be fixed by making the integers a string and using more str_to_num's... im rambling)
is there any way to have this output into a number with commas in it accordingly, like for the last entry
PHP Code:

client_print(idprint_chat, [AMXX] %syou have %s points!",name,CONVERTED_NUMBER) 

any easy formulas I can use in this code? or should I just forget about it?

wrecked_ 06-02-2010 15:56

Re: large numbers, easy comma formula?
 
Search around the Scripting Help subforum. There were multiple threads like this in the past couple of months. I believe some people like Emp`, Bugsy, and Exolent have contributed stocks to getting things like these done.

HLM 06-02-2010 16:39

Re: large numbers, easy comma formula?
 
for those that look here looking for the same thing:

http://forums.alliedmods.net/showthr...ghlight=digits

Seta00 06-02-2010 17:31

Re: large numbers, easy comma formula?
 
Quote:

Originally Posted by HLM (Post 1198303)
for those that look here looking for the same thing:

http://forums.alliedmods.net/showthr...ghlight=digits

I don't think that thread provides the info needed for bignum handling...

Bugsy 06-02-2010 19:43

Re: large numbers, easy comma formula?
 
If your numbers will always be within the signed int32 range ( -2,147,483,648 to 2,147,483,647 ) you can use the below. If the numbers can be outside of this range then this will take a bit more work.

Edit: Discovered -2,147,483,648 is not possible since the positive variant of this is number is 2,147,483,648 which is larger than 2,147,483,647. abs() is used in this function which fails. I have edited the below accordingly.

Result
Code:

-2147483647 = -2,147,483,647

2147483647 = 2,147,483,647

Code from my post in the thread posted above:
PHP Code:

#include <amxmodx>

new iMin = -2147483647;
new 
iMax 2147483647;

public 
plugin_init() 
{
    new 
szNum15 ];
    
    
AddCommasiMin szNum charsmaxszNum ) );
    
server_print"%d = %s" iMin szNum );
    
    
AddCommasiMax szNum charsmaxszNum ) );
    
server_print"%d = %s" iMax szNum );
}

public 
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;



Seta00 06-02-2010 20:00

Re: large numbers, easy comma formula?
 
Again, he wants to manipulate numbers outside the long range, so this comma thing is completely unrelated.
If you really need to manipulate numbers bigger than 2,147,483,648, I can bind some bignum library to Pawn with a small module.

fysiks 06-02-2010 20:08

Re: large numbers, easy comma formula?
 
Quote:

Originally Posted by Seta00 (Post 1198453)
Again, he wants to manipulate numbers outside the long range, so this comma thing is completely unrelated.

Check again, he said middle column. The last number looks like a timestamp or something.

fysiks 06-02-2010 20:13

Re: large numbers, easy comma formula?
 
According to his example code he is just displaying the number as a string with commas.

From Post #3 I assume he has what he wants.

Seta00 06-02-2010 20:24

Re: large numbers, easy comma formula?
 
Quote:

Originally Posted by fysiks (Post 1198462)
Check again, he said middle column. The last number looks like a timestamp or something.

Quote:

Originally Posted by HLM (Post 1198238)
I am now dealing with large numbers
...
highest on record was over 1 billion, we found out it will loop down into the negatives, im assuming that could be fixed

Now I'm confused by the title of the thread... Where are you HLM?

HLM 06-02-2010 20:28

Re: large numbers, easy comma formula?
 
This will work, my main question is answered, but I do have an interest in numbers larger than the int32 base, or whatever it is, I have had 3 or 4 resets due to people saying their points have reset down into the extremely low negatives, for now I have set a cap of 1 billion on the points, but if I can get a nearly infinite base, that would be awesome (why I was presuming calling all numbers a string might help me with this)

case number:
"1": { number = "2" }

etc. ofcourse, I would also need to format it digit by digit too, which would eventually become quite difficult.

does that sum up where im at?


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

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