Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I use this code.It is VB code but you can easily translate it to C#. It works</p> <pre><code>Function NumberToText(ByVal n As Integer) As String Select Case n Case 0 Return "" Case 1 To 19 Dim arr() As String = {"One","Two","Three","Four","Five","Six","Seven", _ "Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen", _ "Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"} Return arr(n-1) &amp; " " Case 20 to 99 Dim arr() as String = {"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"} Return arr(n\10 -2) &amp; " " &amp; NumberToText(n Mod 10) Case 100 to 199 Return "One Hundred " &amp; NumberToText(n Mod 100) Case 200 to 999 Return NumberToText(n\100) &amp; "Hundreds " &amp; NumberToText(n mod 100) Case 1000 to 1999 Return "One Thousand " &amp; NumberToText(n Mod 1000) Case 2000 to 999999 Return NumberToText(n\1000) &amp; "Thousands " &amp; NumberToText(n Mod 1000) Case 1000000 to 1999999 Return "One Million " &amp; NumberToText(n Mod 1000000) Case 1000000 to 999999999 Return NumberToText(n\1000000) &amp; "Millions " &amp; NumberToText(n Mod 1000000) Case 1000000000 to 1999999999 Return "One Billion " &amp; NumberTotext(n Mod 1000000000) Case Else Return NumberToText(n\1000000000) &amp; "Billion " _ &amp; NumberToText(n mod 1000000000) End Select End Function </code></pre> <p>Here is the code in c#</p> <pre><code>public static string AmountInWords(double amount) { var n = (int)amount; if (n == 0) return ""; else if (n &gt; 0 &amp;&amp; n &lt;= 19) { var arr = new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }; return arr[n - 1] + " "; } else if (n &gt;= 20 &amp;&amp; n &lt;= 99) { var arr = new string[] { "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; return arr[n / 10 - 2] + " " + AmountInWords(n % 10); } else if (n &gt;= 100 &amp;&amp; n &lt;= 199) { return "One Hundred " + AmountInWords(n % 100); } else if (n &gt;= 200 &amp;&amp; n &lt;= 999) { return AmountInWords(n / 100) + "Hundred " + AmountInWords(n % 100); } else if (n &gt;= 1000 &amp;&amp; n &lt;= 1999) { return "One Thousand " + AmountInWords(n % 1000); } else if (n &gt;= 2000 &amp;&amp; n &lt;= 999999) { return AmountInWords(n / 1000) + "Thousand " + AmountInWords(n % 1000); } else if (n &gt;= 1000000 &amp;&amp; n &lt;= 1999999) { return "One Million " + AmountInWords(n % 1000000); } else if (n &gt;= 1000000 &amp;&amp; n &lt;= 999999999) { return AmountInWords(n / 1000000) + "Million " + AmountInWords(n % 1000000); } else if (n &gt;= 1000000000 &amp;&amp; n &lt;= 1999999999) { return "One Billion " + AmountInWords(n % 1000000000); } else { return AmountInWords(n / 1000000000) + "Billion " + AmountInWords(n % 1000000000); } } </code></pre>
 

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