CSharp examples for System:String Number
Number To Text
using System.Text.RegularExpressions; using System.Text; using System.Globalization; using System.Collections.Generic; using System;/*from www. j a v a 2 s .c o m*/ public class Main{ public static string NumberToText(int n) { if (n < 0) return "Minus " + NumberToText(-n); else if (n == 0) return ""; else if (n <= 19) return new string[] {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}[n - 1] + " "; else if (n <= 99) return new string[] {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}[n / 10 - 2] + " " + NumberToText(n % 10); else if (n <= 199) return "One Hundred " + NumberToText(n % 100); else if (n <= 999) return NumberToText(n / 100) + "Hundred " + NumberToText(n % 100); else if (n <= 1999) return "One Thousand " + NumberToText(n % 1000); else if (n <= 999999) return NumberToText(n / 1000) + "Thousand " + NumberToText(n % 1000); else if (n <= 1999999) return "One Million " + NumberToText(n % 1000000); else if (n <= 999999999) return NumberToText(n / 1000000) + "Million " + NumberToText(n % 1000000); else if (n <= 1999999999) return "One Billion " + NumberToText(n % 1000000000); else return NumberToText(n / 1000000000) + "Billion " + NumberToText(n % 1000000000); } }