Raised This Month: $ Target: $400
 0% 

large numbers, easy comma formula?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-02-2010 , 15:45   large numbers, easy comma formula?
Reply With Quote #1

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?
__________________
+|- KARMA Respectively

HLM is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-02-2010 , 15:56   Re: large numbers, easy comma formula?
Reply With Quote #2

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.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-02-2010 , 16:39   Re: large numbers, easy comma formula?
Reply With Quote #3

for those that look here looking for the same thing:

http://forums.alliedmods.net/showthr...ghlight=digits
__________________
+|- KARMA Respectively

HLM is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 06-02-2010 , 17:31   Re: large numbers, easy comma formula?
Reply With Quote #4

Quote:
Originally Posted by HLM View Post
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...
Seta00 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-02-2010 , 19:43   Re: large numbers, easy comma formula?
Reply With Quote #5

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;

__________________

Last edited by Bugsy; 11-22-2015 at 07:05.
Bugsy is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 06-02-2010 , 20:00   Re: large numbers, easy comma formula?
Reply With Quote #6

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.
Seta00 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-02-2010 , 20:08   Re: large numbers, easy comma formula?
Reply With Quote #7

Quote:
Originally Posted by Seta00 View Post
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 is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 06-02-2010 , 20:24   Re: large numbers, easy comma formula?
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
Check again, he said middle column. The last number looks like a timestamp or something.
Quote:
Originally Posted by HLM View Post
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?
Seta00 is offline
Old 06-02-2010, 20:11
Bugsy
This message has been deleted by Bugsy.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-02-2010 , 20:13   Re: large numbers, easy comma formula?
Reply With Quote #10

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.
__________________
fysiks 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 05:18.


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