.NET convert number to string representation (1 to one, 2 to two, etc...) -
What is the method to convert a number to represent the string in a .net in the method? For example, 1 becomes one, 2 gets two, etc.
I've always been a fan recursive method
public static string Numberto (int n) {if (n & lt; 0) returns "minus" + numeroytext (-n); Else if (n == 0) "" return; Otherwise, "seven", "eight", "nine" and "if" (n & lt; = 1) new string [] {] "", "two", "three", "four", "five" "Ninja"} [n-1] + "", "ten", "eleven", "twelve", "thirah", "fourteen", "fifteen", "sixteen", "seventeen" ; Otherwise, return the new string [] {"twenty", "thirty", "forty", "fifty", "sixty", "seventh", "eighty", "ninety"} [ N / 10 - 2] + "+ numberto text (n% 10); Else if (n & lt; = 199) "one hundred" + numeroytext (n% 100); And if (n & lt; = 999) Return NumberToText (n / 100) + "Hundreds +" + DataToText (n% 100); And if (n & lt; = 1 999) will return "one thousand" + nototext (n% 1000); Else if (n & lt; = 999999) Back to the number ottext (n / 1000) + "tens of thousands" + number text (n% 1000); And if (n & lt; = 1999999) returns "one million" + numatoacte (n% 1000000); Otherwise, if (n & lt; = 999999999) is returned to Nauticaltext (N / 1000000) + "Lakhs" + NumeriteOuttext (N% 1000000); And if (n & gt; = 199 99 99) will return "one billion" + Nativetext (N% 1000000000); Second number return text (N / 1000000000) + "billion" + Nativetext (N% 1000000000); }
Comments
Post a Comment