View Single Post
mehelp
Junior Member
Join Date: Jul 2011
Old 07-23-2011 , 21:56   Re: Displaying stats issue (adding comma separator)
Reply With Quote #4

Quote:
Originally Posted by berni View Post
PHP Code:
stock FormatNumberInt(valueString:buffer[], sizeseperator='.')
{
    
decl String:helper[size];
    
IntToString(valuehelpersize);
    
strcopy(buffersizehelper);

    new 
length strlen(helper);

    new 
n_helper;

    if (
helper[0] == '-') {
        
n_helper += ((length-1) % 3) + 1;

        if (
n_helper == 1) {
            
n_helper 4;
        }
    }
    else {
        
n_helper += length 3;

        if (
n_helper == 0) {
            
n_helper 3;
        }
    }

    new 
n_buffer n_helper;

    while (
n_helper length) {
        
buffer[n_buffer] = seperator;
        
strcopy(buffer[n_buffer 1], sizehelper[n_helper]);

        
n_buffer += 4;
        
n_helper += 3;
    }

Mathematical version: (bit slower with big numbers)

PHP Code:
stock FormatNumber_(valueString:buffer[], sizeseperator='.')
{
    
buffer[0] = '\0';

    new 
divisor 1000;

    while (
value >= 1000 || value <= -1000) {
        new 
offcut value divisor;
        
value RoundToFloor(float(value) / float(divisor));

        
Format(buffersize"%c%03.d%s"seperatoroffcutbuffer);
    }

    
Format(buffersize"%d%s"valuebuffer);

    return;

Now finally, thank you, sir, thank you very big. That works perfectly. Such a relief to finally have it. You should run for president or something - that's how smart and pretty you are. Even though I didn't get it why is "Mathematical version: " is funnier than non mathematical one (need to learn more bout scripting, which I will go and do right away), laughed like a horse. Thank you, berni, have a nice day. as nice as possible

Last edited by mehelp; 07-23-2011 at 23:05.
mehelp is offline