有没有一种简单的方法可以将数字转换为印度语单词格式与十万分之一和千万卢比?

时间:2010-03-23 23:48:43

标签: c# .net localization numbers

正如标题所示,我想将长号转换为使用C#的单词格式。文化设置似乎没有这样做,我现在正在做这个

String.Format(new CultureInfo("en-IN"), "{0:C0}", Price)

但是对于很长的数字我更喜欢单词格式。我不是来自印度,只是模糊地熟悉系统的运作方式。

3 个答案:

答案 0 :(得分:4)

public static string NumberToWords(int number)
    {
        if (number == 0) { return "zero"; }
        if (number < 0) { return "minus " + NumberToWords(Math.Abs(number)); }
        string words = "";
        if ((number / 10000000) > 0) { words += NumberToWords(number / 10000000) + " Crore "; number %= 10000000; }
        if ((number / 100000) > 0) { words += NumberToWords(number / 100000) + " Lakh "; number %= 100000; }
        if ((number / 1000) > 0) { words += NumberToWords(number / 1000) + " Thousand "; number %= 1000; }
        if ((number / 100) > 0) { words += NumberToWords(number / 100) + " Hundred "; number %= 100; }
        if (number > 0)
        {
            if (words != "") { words += "and "; }
            var unitsMap = new[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
            var tensMap = new[] { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "seventy", "Eighty", "Ninety" };
            if (number < 20) { words += unitsMap[number]; }
            else { words += tensMap[number / 10]; if ((number % 10) > 0) { words += "-" + unitsMap[number % 10]; } }
        }
        return words;
    }

答案 1 :(得分:2)

  • 1 - 一个
  • 10 - 十
  • 1000 - 千
  • 10,000 - 一万
  • 1,00,000 - Lakh
  • 10,00,000 - Ten Lakh
  • 1,00,00,000 - Crore
  • 10,00,00,000 - Ten Crore

..在此之后,阿拉伯人,Kharab,Neel等不在常规使用中。 事实上,即使金融机构也遵循这一点:

  • 100,00,00,000 - 百万卢比
  • 1,000,00,00,000 - 千千万亿
  • 10,000,00,00,000 - 万卢比
  • 1,00,000,00,00,000 - One Lakh Crore(Trillion)
  • 99,00,000,00,00,000 - 九十九Lakh Crore(万亿)

一旦超过这个数字,它们就可以方便地切换到数百万/十亿/万亿/四亿......

答案 2 :(得分:1)

虽然我不能给你代码本身,但这是系统

  • 1 - 一个
  • 10 - 十
  • 1000 - 千
  • 10000 - 一万
  • 100000 - Lakh
  • 1000000 - Ten Lakh
  • 10000000 - Crore
  • 100000000 - Ten Crore
  • 1000000000 - 阿拉伯
  • 10000000000 - 十阿拉伯
  • 100000000000 - Kharab
  • 1000000000000 - Ten Kharab
  • 10000000000000 - 1 Neel
  • 100000000000000 - 10 Neel
  • 1000000000000000 - 1 Padm

我已经为我制作的会计软件包写了例程,所以编写它并不是特别难。