Don't like ads? PRO users don't see any ads ;-)
Guest

cpp_pawn

By: Niko_boy on May 6th, 2012  |  syntax: PAWN  |  size: 3.54 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. public NumberToText(const only_number[], const outputString[])
  3. {
  4.     new one_array[10][11] = {
  5.         " ","one ", "two ", "three ", "four ", "five ","six ", "seven ", "eight ", "nine "
  6.         };
  7.     new ten_array[10][11] = {
  8.                 "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ",
  9.                 "seventeen ", "eighteen ", "nineteen "
  10.         };
  11.     new twenty_array[10][11] = {
  12.         " "," ","twenty ", "thirty ", "fourty ", "fifty ", "sixty ", "seventy ", "eighty ", "ninety "
  13.         };
  14.         new big_unit_array[22][20] = {"vigintillion","novemdecillion","octodecillion","septendecillion",
  15.                                            "sexdecillion","quindecillion","quattuordecillion","tredecillion",
  16.                                                                    "duodecillion","undecillion","decillion","nonillion","octillion",
  17.                                                                    "septillion","sextillion","quintillion","quadrillion","trillion ",
  18.                                                                    "billion ", "million ", "thounsand ", "hundred "};
  19.         #define MaxUnit 21
  20.         new tempString[150][20];
  21.         //E.g. 1,234,567,890,123
  22.         new i; //for only_number
  23.         new j; //for tempString
  24.         new rem;
  25.         new sizeofNumber = strlen(only_number);
  26.         new tflag = 0;
  27.         for(i = 0,j = 0; i<sizeofNumber; i++)
  28.         {
  29.                 rem = (sizeofNumber-i)%3;
  30.                 if(!rem)
  31.                         tflag = 0;
  32.                 if(only_number[i] != '0')
  33.                 {
  34.                         if(rem == 1) //in oneth position
  35.                         {
  36.                 strmid(tempString[j++],one_array[only_number[i]-48]);
  37.                                 tflag = 1;
  38.                         }
  39.                         else if(rem == 2)
  40.                         { //in tenth position
  41.                 if(only_number[i] == '1')
  42.                                         strmid(tempString[j++],ten_array[only_number[++i]-48]);
  43.                 else
  44.                                         strmid(tempString[j++],twenty_array[only_number[i]-48]);
  45.                                 tflag = 1;
  46.             }
  47.             else if(rem == 0)
  48.                         {// in hundredth position
  49.                                 strmid(tempString[j++],one_array[only_number[i]-48]);
  50.                                 strmid(tempString[j++],big_unit_array[MaxUnit]);
  51.                                 tflag = 1;
  52.                         }
  53.                 }
  54.                 if(tflag)
  55.                 {
  56.                         switch(sizeofNumber-i)
  57.                         {
  58.                         case 64: { strmid(tempString[j++],big_unit_array[MaxUnit-21]); break; }
  59.                         case 61: {  strmid(tempString[j++],big_unit_array[MaxUnit-20]); break; }
  60.                         case 58: {  strmid(tempString[j++],big_unit_array[MaxUnit-19]); break; }
  61.                         case 55: {  strmid(tempString[j++],big_unit_array[MaxUnit-18]); break; }
  62.                         case 52: {  strmid(tempString[j++],big_unit_array[MaxUnit-17]); break; }
  63.                         case 49: { strmid(tempString[j++],big_unit_array[MaxUnit-16]); break; }
  64.                         case 46: { strmid(tempString[j++],big_unit_array[MaxUnit-15]); break; }
  65.                         case 43: { strmid(tempString[j++],big_unit_array[MaxUnit-14]); break; }
  66.                         case 40: { strmid(tempString[j++],big_unit_array[MaxUnit-13]); break; }
  67.                         case 37: { strmid(tempString[j++],big_unit_array[MaxUnit-12]); break; }
  68.                         case 34: { strmid(tempString[j++],big_unit_array[MaxUnit-11]); break; }
  69.                         case 31: { strmid(tempString[j++],big_unit_array[MaxUnit-10]); break; }
  70.                         case 28: { strmid(tempString[j++],big_unit_array[MaxUnit-9]); break; }
  71.                         case 25: { strmid(tempString[j++],big_unit_array[MaxUnit-8]); break; }
  72.                         case 22: { strmid(tempString[j++],big_unit_array[MaxUnit-7]); break; }
  73.                         case 19: { strmid(tempString[j++],big_unit_array[MaxUnit-6]); break; }
  74.                         case 16: { strmid(tempString[j++],big_unit_array[MaxUnit-5]); break; }
  75.                         case 13: { strmid(tempString[j++],big_unit_array[MaxUnit-4]); break; }
  76.                         case 10: { strmid(tempString[j++],big_unit_array[MaxUnit-3]); break; }
  77.                         case 7 : { strmid(tempString[j++],big_unit_array[MaxUnit-2]); break; }
  78.                         case 4 : { strmid(tempString[j++],big_unit_array[MaxUnit-1]); break; }
  79.                         }
  80.                 }
  81.         }
  82.         j--;
  83.         strmid(outputString,tempString[0]);
  84.         for(new i=1; new i<=j; i++)
  85.                 strcat(outputString, tempString[i]);
  86. }