Notifications
                
            
                Clear all
    
            
        [Closed] Insert comma into a string?
Sep 21, 2007 12:26 am
                      Hey guys, i’m trying to figure out somethign that… in theory seems simple to me but i just can’t seem to solve it.
I have a number generated for me, and i’d like it to be all comma seperated every 3 digits.
So say right now i have
theNumber = “3879”
i was trying to use a substring, but that seemed to work going from the left, but I’m quite sure i’d neat to start counting numbers from the right (incase i have like 10 numbers or 5)
Any simple way i’m totaly missing to make my number go from “3879” to “3,879”?
Thanks guys
                             2 Replies                        
                    Sep 21, 2007 12:26 am
                      Don’t know of a built in method, but this should do it:
fn ToDecimalString str digits =
(
    local result = ""
    for i = str.count to 1 by -1 do
    (
        if mod i digits == 0 and str.count != i do result += ","
        result += str[str.count - i + 1]
    )
    result
)
Light