ID:257774   Mar 7 2010, 8:09 am I present a grossly imperfect Number2Text proc that, while it can do the job, I think many of you can do way better than I can. To be honest I was only interested in the first ten digits, which AFAIK need to be manually specified anyway. If anyone can make this proc better, please do! It'll help me learn and it'll help others out. ```/*Title: Number2TextCredit to: Android DataContributed by: Android DataThis function returns the text form of any number you specify, so long as it's under a hundred.*/proc/Number2Text(n) switch(n) if(0) return "zero" if(1) return "one" if(2) return "two" if(3) return "three" if(4) return "four" if(5) return "five" if(6) return "six" if(7) return "seven" if(8) return "eight" if(9) return "nine" if(10) return "ten" if(11) return "eleven" if(12) return "twelve" if(13) return "thirteen" if(14) return "fourteen" if(15) return "fifteen" if(16) return "sixteen" if(17) return "seventeen" if(18) return "eighteen" if(19) return "nineteen" else if(n >= 20 && n < 30) return "twenty-[Number2Text(n - 20)]" else if(n >= 30 && n < 40) return "thirty-[Number2Text(n - 30)]" else if(n >= 40 && n < 50) return "fourty-[Number2Text(n - 40)]" else if(n >= 50 && n < 60) return "fifty-[Number2Text(n - 50)]" else if(n >= 60 && n < 70) return "sixty-[Number2Text(n - 60)]" else if(n >= 70 && n < 80) return "seventy-[Number2Text(n - 70)]" else if(n >= 80 && n < 90) return "eighty-[Number2Text(n - 80)]" else if(n >= 90 && n < 100) return "ninety-[Number2Text(n - 90)]" else if(n >= 100 && n < 1000) . = round(n / 100) var/b = n - (. * 100) return "[Number2Text(.)] hundred[b > 0 ? " and [Number2Text(b)]":]" ```
 <-> Jul 28 2010, 9:09 pm Minor thing to note, especially for a thread that's been gone for a while, is that you can specify a range of numerical values in switch() with the 'to' operator: ```proc/Number2Text(n) switch(abs(n)) if(0) . = "zero" if(1) . = "one" if(2) . = "two" if(3) . = "three" if(4) . = "four" if(5) . = "five" if(6) . = "six" if(7) . = "seven" if(8) . = "eight" if(9) . = "nine" if(10) . = "ten" if(11) . = "eleven" if(12) . = "twelve" if(13) . = "thirteen" if(14) . = "fourteen" if(15) . = "fifteen" if(16) . = "sixteen" if(17) . = "seventeen" if(18) . = "eighteen" if(19) . = "nineteen" if(20 to 29) . = "twenty-[Number2Text(n - 20)]" if(30 to 39) . = "thirty-[Number2Text(n - 30)]" if(40 to 49) . = "fourty-[Number2Text(n - 40)]" if(50 to 59) "fifty-[Number2Text(n - 50)]" if(60 to 69) . = "sixty-[Number2Text(n - 60)]" if(70 to 79) . = "seventy-[Number2Text(n - 70)]" if(80 to 89) . = "eighty-[Number2Text(n - 80)]" if(90 to 99) . = "ninety-[Number2Text(n - 90)]" if(100 to 999) var/i = round(n / 100) var/b = n - (i * 100) . = "[Number2Text(i)] hundred[b > 0 ? " and [Number2Text(b)]":]" else CRASH("Something is wrong!") if(n < 0) . += "negative " ```
 <-> Sep 26 2010, 3:00 am In response to GhostAnime GhostAnime wrote: Minor thing to note ```> . = "[Number2Text(i)] hundred[b > 0 ? " and [Number2Text(b)]":]"> ``` The mathematic-politically correct value here would not include "and" in the name; "and" is used to mark the decimal point; at least, that's true here in the US, but I'm not sure about elsewhere in the world. So 123.45 comes to "One hundred twenty-three and forty-five hundredths."