ID:2081138
 
(See the best response by Ter13.)
My items are displayed on screen with maptext of the stack amount, Having a problem with large numbers over 999. How would i go about breaking this down to something like this example: 1.2k , 1.5M, 10M , 1B?
Best response
proc/stacktext(num)
if(num<1000)
return "[num]"
else if(num<10000)
return "[round(num/100)/10]K"
else if(num<1000000)
return "[round(num/1000)]K"
else if(num<10000000)
return "[round(num/100000)/10]M"
else if(num<1000000000)
return "[round(num/1000000)]M"
else if(num<10000000000)
return "[round(num/100000000)/10]B"
else
return "[round(num/1000000000)]B"


BYOND doesn't deal with really big numbers very well though. You are going to get inaccuracy when adding small numbers to very large numbers because of floating point limitations.
Thank you
This also works for Maptext damage numbers, btw is there a way to make maptext look pretty? Instead of the default as if you would manual craft every letter?
You can adjust the font for the map in the interface editor or use html
maptext supports full HTML (And I believe partial CSS? Don't quote me on that) formatting.

maptext = "<font color=red>This is red!"
maptext = "<font face=Verdana>This is a different font!"
maptext = "<font face=Verdana color=red>This is red and a different font!"
As Ter13 alluded to, BYOND can only natively handle positive integers accurately up to 16,777,215. If you think that you're going to have to actually need to store numbers larger than that accurately to single digit precision, then my pif_LongInt library can be useful to you. Right now, unsigned integers are accurate up to 4,294,967,295 (i.e., 256 times more accurate than BYOND can natively handle), and future updates will increase that accuracy to 281,474,976,710,655 and then 18,446,744,073,709,551,615 (probably far larger than you'd ever need to worry about).
In response to Popisfizzy
Actually it can handle 16,777,216 as well, since that's a power of 2; it's past that where the breakdown occurs.
In response to Lummox JR
Whoops, yeah, my mistake.