Raised This Month: $ Target: $400
 0% 

Add some points on a Integer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 03-11-2010 , 13:30   Add some points on a Integer
Reply With Quote #1

How i can do something like this on a integer:

165 -> 165 (rofl)
3450 -> 3.450
172834 -> 172.834
1938294029 -> 1.938.294.029

(being a string, obviusly)

Thanks in advance. (:
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
worldspawn
Senior Member
Join Date: Aug 2009
Location: Russia, Yekaterinburg
Old 03-11-2010 , 13:32   Re: Add some points on a Integer
Reply With Quote #2

sorry for offtop but what for?
worldspawn is offline
Send a message via ICQ to worldspawn Send a message via Skype™ to worldspawn
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-11-2010 , 13:49   Re: Add some points on a Integer
Reply With Quote #3

Code:
InsertCharacter( szInput[], iLoc, iChar, szOutput[], iLen )
{
    copy(szOutput, iLen, szInput);
    if( iLoc < iLen )
    {
        szOutput[iLoc] = iChar;
        copy(szOutput[iLoc+1], iLen-(iLoc+1), szInput[iLoc]);
    }
}
Untested. Usage:
Code:
InsertCharacter( "12345", 2, '.', blah, charsmax(blah));
// blah == "12.345"

Last edited by Emp`; 03-11-2010 at 13:52.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 03-11-2010 , 13:58   Re: Add some points on a Integer
Reply With Quote #4

Quote:
Originally Posted by worldspawn View Post
sorry for offtop but what for?
Why i must tell you? o.O

Quote:
Originally Posted by Emp` View Post
Code:
InsertCharacter( szInput[], iLoc, iChar, szOutput[], iLen )
{
    copy(szOutput, iLen, szInput);
    if( iLoc < iLen )
    {
        szOutput[iLoc] = iChar;
        copy(szOutput[iLoc+1], iLen-(iLoc+1), szInput[iLoc]);
    }
}
Untested. Usage:
Code:
InsertCharacter( "12345", 2, '.', blah, charsmax(blah));
// blah == "12.345"
What is the usage of the second parameter?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 03-11-2010 , 13:59   Re: Add some points on a Integer
Reply With Quote #5

At which character index you want to insert the third parameter.
E.g.: 2 means insert third parameter after the second char of the string (index 2)
Seta00 is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 03-11-2010 , 14:34   Re: Add some points on a Integer
Reply With Quote #6

It works, but i don't need that...

I need if can be done automatically, something like this:

PHP Code:
InsertPointChars(13274buffercharsmax(buffer)) // buffer = "13.274"
InsertPointChars(200000buffercharsmax(buffer)) // buffer = "200.000"
InsertPointChars(58963214buffercharsmax(buffer)) // buffer = "58.963.214" 
On every 3 last numbers...
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 03-11-2010 , 15:22   Re: Add some points on a Integer
Reply With Quote #7

Code:
InsertPointChars( num, szOutput[], iLen )
{
    num_to_str( num, szOutput, iLen );
    for( new len = strlen(szOutput)-3; len > 0; len-=3 )
    {
        copy(szOutput[len+1], iLen-(len+1), szOutput[len]);
        szOutput[len] = '.';
    }
}
Untested.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-11-2010 , 18:28   Re: Add some points on a Integer
Reply With Quote #8

Oh I see what you want.
You don't use periods for this, you use commas.

Code:
AddCommas(const input[], output[], const len) {     new stop = contain(input, ".");         if(stop == -1)     {         stop = strlen(input);     }         new o, i;     while(i < stop && o < len)     {         output[o++] = input[i++];                 if(o < len && i < stop && ((stop - i) % 3) == 0)         {             output[o++] = ',';         }     }         if(o < len)     {         o += copy(output[o], len - o, input[stop]);     }         return o; }

Works for both integers and floats.

Code:
new iNum = 123456; new szNum[ 12 ]; num_to_str( iNum, szNum, charsmax( szNum ) ); new szNumComma[ 15 ]; AddCommas( szNum, szNumComma, charsmax( szNumComma ) ); client_print( 0, print_chat, "%i is %s", iNum, szNumComma );

Code:
new Float:fNum = 123.456; new szNum[ 16 ]; float_to_str( fNum, szNum, charsmax( szNum ) ); new szNumComma[ 19 ]; AddCommas( szNum, szNumComma, charsmax( szNumComma ) ); client_print( 0, print_chat, "%f is %s", fNum, szNumComma );
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 04-06-2011 at 00:53.
Exolent[jNr] is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 03-11-2010 , 20:09   Re: Add some points on a Integer
Reply With Quote #9

Oh damn, you rocks Exolent

I'll test later, because i am not on my pc

Thanks Emp` too, maybe i'll use your stock for other things (:
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross

Last edited by meTaLiCroSS; 03-11-2010 at 20:11.
meTaLiCroSS is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 03-11-2010 , 20:50   Re: Add some points on a Integer
Reply With Quote #10

If you want a shorter stuff.
PHP Code:
    //Number must be the number that you want to pointed (integrer)
    
new str[15], strpointed[15], len
    num_to_str
(numberstr14)
    
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)
    }
//strpointed is the number with '.' 

Last edited by Mxnn; 03-12-2010 at 11:28.
Mxnn 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