Raised This Month: $ Target: $400
 0% 

Error with "pointing" a string number


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 12-30-2009 , 10:12   Error with "pointing" a string number
Reply With Quote #1

I have a number, for example 1234. I want to show it like 1.234 (American people use 1,234)

I was trying with this
PHP Code:
    new str1[15]
    
num_to_str(numberstr114)
    new 
len strlen(str1)
    while(
len 3)
    {
        
len -= 3
        add
(str1len,".")
    } 
But that just produces random shit.

Last edited by 01101101; 12-30-2009 at 13:57.
01101101 is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 12-30-2009 , 11:00   Re: Error with "pointing" a string number
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?go=func&id=48
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 12-30-2009 , 11:02   Re: Error with "pointing" a string number
Reply With Quote #3

Quote:
Originally Posted by Owyn View Post
Whats wrong with it, I don't get it.
01101101 is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-30-2009 , 13:43   Re: Error with "pointing" a string number
Reply With Quote #4

In the first line you have a "," plus.
Mxnn is offline
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 12-30-2009 , 13:57   Re: Error with "pointing" a string number
Reply With Quote #5

Quote:
Originally Posted by Mxnn View Post
In the first line you have a "," plus.
Nevermind, that was just a typo when I wrote the code here.
01101101 is offline
Old 12-30-2009, 14:10
SnoW
This message has been deleted by SnoW.
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-30-2009 , 18:36   Re: Error with "pointing" a string number
Reply With Quote #6

If you want to show the number you can do this:
PHP Code:
    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 '.' 
Test it. I don't remember if ^n is counted in strlen

EDIT: Is tested and it works for me.

Last edited by Mxnn; 12-30-2009 at 19:10.
Mxnn is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 12-30-2009 , 21:40   Re: Error with "pointing" a string number
Reply With Quote #7

Also tested and confirmed Mxnn. Anyway did my version of it (it should be a little faster):

PHP Code:
public convertNumber(numAsString[],numAsStringFormatted[])
{
    new 
len strlen(numAsString
    static 
startValue[] = {3,1,2}
    new 
start startValue[len 3]
    
    
copy(numAsStringFormatted,start,numAsString)
    
    if(
len 3)
    {
        new 
totalLen len + ((len-1) / 3)

        
add(numAsStringFormatted,totalLen,".")
        
        new 
i
        
for(i=start;i<len-3;i+=3)
        {
            
add(numAsStringFormatted,totalLen,numAsString[i],3)
            
add(numAsStringFormatted,totalLen,".")
        }
        
        
add(numAsStringFormatted,totalLen,numAsString[i],3)
    }


Last edited by joaquimandrade; 12-30-2009 at 21:51.
joaquimandrade is offline
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 12-30-2009 , 23:27   Re: Error with "pointing" a string number
Reply With Quote #8

Yes, Mxnn version works fine. Haven't tried your version quim, dunno which will be faster in my case. I am "converting" 2 numbers which are 99% higher than 1000, and sometimes higher than 1000000, each time a players shoots and hits somebody. Considering that its a 32 slots zombie plague server in which people shoot like crazy, this, may affect (slightly) server perfonmance.

If I can, I'll profile both methods to see the difference.

Thanks both of you.
01101101 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 04:14.


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