正如标题所示,我想将长号转换为使用C#的单词格式。文化设置似乎没有这样做,我现在正在做这个
String.Format(new CultureInfo("en-IN"), "{0:C0}", Price)
但是对于很长的数字我更喜欢单词格式。我不是来自印度,只是模糊地熟悉系统的运作方式。
答案 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)
..在此之后,阿拉伯人,Kharab,Neel等不在常规使用中。 事实上,即使金融机构也遵循这一点:
一旦超过这个数字,它们就可以方便地切换到数百万/十亿/万亿/四亿......
答案 2 :(得分:1)
虽然我不能给你代码本身,但这是系统
我已经为我制作的会计软件包写了例程,所以编写它并不是特别难。