Commas

By Ssj4justdale on Aug 31, 2009

Ever wanted to add commas to your numbers. Say you got 100000 as a displaying number and you want to convert it to 100,000? Here's the code.

proc/applycommas(number)
    number=num2text(number,1000000)
    var/digits=length(number)
    var/remaining=0
    var/returnnumber
    while(digits>=1)
        if(digits>3)
            var/end=","+copytext(number,digits-2,digits+1)
            var/get=end
            returnnumber=get+returnnumber
            remaining=(length(get)-1)+remaining
            digits-=3
        else
            var/get=copytext(number,1,(length(number)+1)-remaining)
            returnnumber=get+returnnumber
            digits=0
    return returnnumber

Comments

Sign in to comment.
Mirccoder   -  Mar 16, 2010

I didnt know you did byond Dale but liekt eh snippet

Ssj4justdale  -  Jul 18, 2013

haha sorry for the 3 year late response but thanks :D

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.