ID:152950
 
I hate the way BYOND uses Scientific Notation when you have numbers 7 or more digits. Thats why I made a proc to convert all numbers to text so it wouldnt do that. But its kinda hard to tell how much you have at a glance if its a large number. I need a way to input commas into the text. Any suggestions?
proc
Add_Comma(N)
N=num2text(N,10)
if(lentext(N)<4)return N
var {Final;At;Temp}
for(var/i=lentext(N),i>0,i--)
At++
if(At==4)
At=1;Temp+=","
Temp+=copytext(N,i,i+1)
for(var/i=lentext(Temp),i>0,i--)
Final+=copytext(Temp,i,i+1)
.=Final
In response to Crashed
Here's my take on it (slightly cleaner IMO). This one assumes you've already converted to text:

proc/commas(T)
// Account for decimals
var/result=""
var/dotpos=findtext(T,".")
if (dotpos)
result=copytext(T,dotpos)
T=copytext(T,1,dotpos)
// Insert commas
var/addednum=0
while(length(T))
if (addednum && T!="-" && T!="+") result=","+result
addednum=1
result=copytext(T,max(1,length(T)-2))+result
T=copytext(T,1,max(1,length(T)-2))
return result


Has been tested, and works fine.

Edit: Now supports decimal numbers and negative numbers. Commas are not added to the decimal portion.
In response to Crispy
Test it with -100.23 :)
In response to Theodis
Bah, I forgot about decimals. =P

In my defence, Crashed did too...

Anyway, I'll fix that.
My kunarklib library has the k_instert_commas() proc, if you want to see it.

it works like a charm. Just use it for display only. I use it in Drugwars if you want to see it in action.