//Title: Comma-Separated Numbers
//Credit to: Jtgibson
//Contributed by: Jtgibson
//This proc converts one of BYOND's standard numerals
// into a comma-separated numeral.
//Be forewarned -- large numbers will almost always have
// rounding error, and may not be exactly what you input.
// This is not the fault of num2commas, but rather the
// fault of the 32-bit floating point number storage
// that computers use. If you want to get rid of the
// inaccuracy, invent a new number storage system and
// tell Intel or AMD about it!
proc/num2commas(num)
var/whole_num = round(num)
var/string = num2text(round(whole_num,1),20)
var/string_len = lentext(string)
for(var/i = string_len-2, i > 1, i -= 3)
string = "[copytext(string,1,i)],[copytext(string,i)]"
return string
///*
//Testing code/sample implementation:
mob/verb/test_num2commas(num as num)
usr << num2commas(num)
//*/
ID:195107
Nov 21 2006, 8:21 am
|
|