将整数转换为单词 [英] converting Integer To Words

查看:73
本文介绍了将整数转换为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将整数值转换为单词:
例如:1020 =一千二十个

how convert integer value to words:
eg: 1020=Thousand and twenty

推荐答案

尝试这个

致电
AmountInWords obj = new AmountInWords();
obj.Convert(10450.67)


AmountinWords.cs

try this

Call
AmountInWords obj=new AmountInWords();
obj.Convert(10450.67)


AmountinWords.cs

class AmountInWords
   {
       private static String[] units = { "Zero", "One", "Two", "Three",
           "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
           "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
           "Seventeen", "Eighteen", "Nineteen" };
       private static String[] tens = { "", "", "Twenty", "Thirty", "Forty",
           "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };


       public String ConvertAmount(double amount)
       {
           try
           {
               int amount_int = (int)amount;
               int amount_dec = (int)Math.Round((amount - (double)(amount_int)) * 100);
               return  convert(amount_int) + "  point "
                       + convert(amount_dec) ;
           }
           catch (Exception e)
           {
               // TODO: handle exception
           }
           return "";
       }

       public String convert(int i)
       {
           //
           if (i < 20)
               return units[i];
           if (i < 100)
               return tens[i / 10] + ((i % 10 > 0) ? " " + convert(i % 10) : "");
           if (i < 1000)
               return units[i / 100] + " Hundred"
                       + ((i % 100 > 0) ? " and " + convert(i % 100) : "");
           if (i < 100000)
               return convert(i / 1000) + " Thousand "
                       + ((i % 1000 > 0) ? " " + convert(i % 1000) : "");
           if (i < 10000000)
               return convert(i / 100000) + " Lakh "
                       + ((i % 100000 > 0) ? " " + convert(i % 100000) : "");
           return convert(i / 10000000) + " Crore "
                   + ((i % 10000000 > 0) ? " " + convert(i % 10000000) : "");
       }

   }


看看这篇CP文章
将数字转换为英语和亚洲格式的单词 [ ^ ]

将VB.net代码转换为C#此处 [
Take a look at this CP article
Convert numbers to words in English and Asian format[^]

Convert VB.net code to C# here[^]


我已经编写了程序将货币转换为字符串.
对该程序进行一点点修改就可以完成您的工作.

I have written the program to convert currency to string.
little bit modifications to this program will do your work.

class Program
    {
        static void Main(string[] args)
        {
            string ammount=string .Empty ;
        Rep:
            Console.WriteLine("Enter the Ammount");
            ammount = Console.ReadLine();
            Regex r=new Regex (@"^[0-9]+(\.[0-9]+)?


这篇关于将整数转换为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆