RE: Formating numbers using commas?

new topic     » goto parent     » topic index » view thread      » older message » newer message

> Any ideas or tips would be appreciated.
> 
> Thanks!

Ahh I just love these little gems.  Really gives the brain a good decent 
workout and hones the problem solving skill set.  Well (of course) I 
just had to poke around with it and this is what I came up with...

Did not do any comparisons (speed or otherwise) to those algos already 
posted.

-=-=-=-=-=-=-=-=-

function AddCommas( atom above )
    atom below
    sequence answer

    answer = {}
    while above do
        below = remainder( above, 1000 )
        above = floor( above / 1000 )
        if above then
            answer = sprintf(",%03d",{below}) & answer
        end if
    end while
    return( sprint(below) & answer )
end function

-=-=-=-=-=-=-=-=-

Enjoy!
Don

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu