Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://www.exchangecore.com/blog/convert-number-words-c-sharp-console-application/" rel="nofollow">http://www.exchangecore.com/blog/convert-number-words-c-sharp-console-application/</a> has some C# script that looks to handle very large numbers and very small decimals.</p> <pre><code>using System; using System.Collections.Generic; using System.Text; namespace NumWords { class Program { // PROGRAM HANDLES NEGATIVE AND POSITIVE DOUBLES static String NumWordsWrapper(double n) { string words = ""; double intPart; double decPart = 0; if (n == 0) return "zero"; try { string[] splitter = n.ToString().Split('.'); intPart = double.Parse(splitter[0]); decPart = double.Parse(splitter[1]); } catch { intPart = n; } words = NumWords(intPart); if (decPart &gt; 0) { if (words != "") words += " and "; int counter = decPart.ToString().Length; switch (counter) { case 1: words += NumWords(decPart) + " tenths"; break; case 2: words += NumWords(decPart) + " hundredths"; break; case 3: words += NumWords(decPart) + " thousandths"; break; case 4: words += NumWords(decPart) + " ten-thousandths"; break; case 5: words += NumWords(decPart) + " hundred-thousandths"; break; case 6: words += NumWords(decPart) + " millionths"; break; case 7: words += NumWords(decPart) + " ten-millionths"; break; } } return words; } static String NumWords(double n) //converts double to words { string[] numbersArr = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; string[] tensArr = new string[] { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninty" }; string[] suffixesArr = new string[] { "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion", "tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septdecillion", "Octodecillion", "Novemdecillion", "Vigintillion" }; string words = ""; bool tens = false; if (n &lt; 0) { words += "negative "; n *= -1; } int power = (suffixesArr.Length + 1) * 3; while (power &gt; 3) { double pow = Math.Pow(10, power); if (n &gt;= pow) { if (n % pow &gt; 0) { words += NumWords(Math.Floor(n / pow)) + " " + suffixesArr[(power / 3) - 1] + ", "; } else if (n % pow == 0) { words += NumWords(Math.Floor(n / pow)) + " " + suffixesArr[(power / 3) - 1]; } n %= pow; } power -= 3; } if (n &gt;= 1000) { if (n % 1000 &gt; 0) words += NumWords(Math.Floor(n / 1000)) + " thousand, "; else words += NumWords(Math.Floor(n / 1000)) + " thousand"; n %= 1000; } if (0 &lt;= n &amp;&amp; n &lt;= 999) { if ((int)n / 100 &gt; 0) { words += NumWords(Math.Floor(n / 100)) + " hundred"; n %= 100; } if ((int)n / 10 &gt; 1) { if (words != "") words += " "; words += tensArr[(int)n / 10 - 2]; tens = true; n %= 10; } if (n &lt; 20 &amp;&amp; n &gt; 0) { if (words != "" &amp;&amp; tens == false) words += " "; words += (tens ? "-" + numbersArr[(int)n - 1] : numbersArr[(int)n - 1]); n -= Math.Floor(n); } } return words; } static void Main(string[] args) { Console.Write("Enter a number to convert to words: "); Double n = Double.Parse(Console.ReadLine()); Console.WriteLine("{0}", NumWordsWrapper(n)); } } } </code></pre> <p>EDIT: brought code over from blog post</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload