Download or view commaify.frink in plain text format
/** Writes an integer with commas seperating the thousands places. */
commaify[n] :=
{
result = new array
for chunk = chunks[reverse[integerDigits[n]],3]
result.pushFirst[joinstr[reverse[chunk]]]
return join[",", result]
}
/*
println[commaify[1]]
println[commaify[12]]
println[commaify[123]]
println[commaify[1234]]
println[commaify[12345]]
println[commaify[123456]]
println[commaify[1234567]]
println[commaify[12345678]]
println[commaify[123456789]]
println[commaify[1234567890]]
println[commaify[12345678901]]
println[commaify[123456789012]]
*/
Download or view commaify.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen, eliasen@mindspring.com