commas scriptlet request

suraimu

New member
Looking for a script routine to take a given integer and add the proper number of commas to it.

Example:

input: 123456789
output: 123,456,789

Been trying to write this for a while and I keep messing it up in peculiar ways. :p
 

macman104

Member
Uh...where are you planning on using this? I'm not sure how this relates to kolmafia scripting?

If it's for mall pricing and stuff, onetontomato has a meat checker type thing that does something similar to this...
 

holatuwol

Developer
My guess is that it's for logging meat totals before/after a meat farming session.

PHP:
string format( int i )
{
    if ( i < 1000 )
        return "" + i;

    int mod = 0;

    string piece = "";
    string result = "";

    while ( i >= 1000 )
    {
        mod = i % 1000;

        if ( mod < 10 )
            piece = "00" + mod;
        else if ( mod < 100 )
            piece = "0" + mod;
        else
            piece = "" + mod;

        if ( result == "" )
            result = piece;
        else
            result = piece + "," + result;

        i = i - (i % 1000);
        i = i / 1000;
    }

    if ( i != 0 )
        result = i + "," + result;

    return result;
}
 

hippymon

Member
[quote author=suraimu link=topic=918.msg4519#msg4519 date=1178901488]
Looking for a script routine to take a given integer and add the proper number of commas to it.

Example:

input: 123456789
output: 123,456,789

Been trying to write this for a while and I keep messing it up in peculiar ways. :p
[/quote]

There is a greasemonkey user script that does this for you:
http://www.greasespot.net/ (greasemonkey)
http://forums.kingdomofloathing.com/viewtopic.php?t=46936 (Script on the forums)
 

suraimu

New member
[quote author=holatuwol link=topic=918.msg4527#msg4527 date=1178918454]
My guess is that it's for logging meat totals before/after a meat farming session.
[/quote]

Among other things, yes. I have my clanbot keep record of a hell of a lot of things and wanted to pretty it up a bit.

Thanks! :)
 
Top