以文字显示数值 [英] Display in words the numerical value

查看:52
本文介绍了以文字显示数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有
我正在与财务公司合作,在该公司中我还需要用文字显示交易金额.这无法解决此问题,需要帮助....
在此先感谢所有人....
Pratham

Dear All
I am working with the finance firm in which i need to display the deal amount in words also .this i am not able to do need Help to resolve this issue for this issue ....
Thanks in advance to all....
Pratham

推荐答案

嗨pratham ..
从1到19999都可以正常工作,一旦扔掉就可以了.

hi pratham..
this works fine from 1 to 19999, once go throw it..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace tryingstartfror4digits
{
class Program
{
    static void Main(string[] args)
    {
        Program pg=new Program();
        Console.WriteLine("Enter ur number");
        int num = Convert.ToInt32(Console.ReadLine());
        if (num <= 19)
        {
            string g = pg.first(num);
            Console.WriteLine("The number is " + g);
        }
        else if ((num >= 20) && (num <= 99))
        {
                if (num % 10 == 0)
                {
                    string g = pg.second(num / 10);
                    Console.WriteLine("The number is " + g);
                }
                else
                {
                    string g = pg.second(num / 10) + pg.first(num % 10);
                    Console.WriteLine("The number is " + g);
                }
          }
        else if((num>=100) && (num<=999))
        {
            int k = num % 100;
            string g = pg.first(num / 100) +pg.third(0) + pg.second(k / 10)+pg.first(k%10);
            Console.WriteLine("The number is " + g);
          }
        else if ((num >= 1000) && (num <= 19999))
        {
            int h=num%1000;
           int k=h%100;
            string g = pg.first(num / 1000) + "Thousand " + pg.first(h/ 100) + pg.third(k) + pg.second(k / 10) + pg.first(k % 10);
            Console.WriteLine("The number is " + g);
        }
        Console.ReadLine();
    }
     public string first(int num)
    {
        string name;
        if (num == 0)
        {
            name = " ";
        }
        else
        {
            string[] arr1 = new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" , "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
            name = arr1[num - 1];
        }
        return name;
    }
    public string second(int num)
    {
        string name;
        if ((num == 0)||(num==1))
        {
         name = " ";
        }
        else
        {
            string[] arr1 = new string[] { "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
            name = arr1[num - 2];
        }
        return name;
    }
    public string third(int num)
    {
        string name ;
        if (num == 0)
        {
            name = "";
        }
        else
        {
            string[] arr1 = new string[] { "Hundred" };
            name = arr1[0];
        }
        return name;
    }

}
}





最好的...:)



all the best...:)




请检查下面的链接.

http://stackoverflow.com/questions/2729752/converting-numbers-in- to-words-c-sharp [ ^ ]

问候,
Raghu
Hi,

Please Check the link below.

http://stackoverflow.com/questions/2729752/converting-numbers-in-to-words-c-sharp[^]

Regards,
Raghu


http://stackoverflow. com/questions/2729752/converting-numbers-in-to-words-c-sharp [

这篇关于以文字显示数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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