【发布时间】:2014-01-27 19:54:33
【问题描述】:
这是下面用于将数字转换为单词的代码。究竟是什么问题?英语的一切都很好,但在我的国家(罗马尼亚)有不同的拼写,让我们用几个例子来说明一下:
例如。 1 - 英语,一美元,一千,一百,两百你就是这样写的 罗马尼亚语,Un Dollar,O mie,O suta,Doua Sute,Trei Sute,单词上有复数变化,在英语中,几乎所有罗马尼亚语都使用 One,这会发生变化,我不知道如何修复这个复数.谢谢
private static string[] _ones =
{
"",
"unu",
"doua",
"trei",
"patru",
"cinci",
"sase",
"sapte",
"opt",
"noua"
};
private static string[] _teens =
{
"zece",
"unsprezece",
"doisprezece",
"treisprezece",
"paisprezece",
"cincisprezece",
"saisprezece",
"saptisprezece",
"optsprezece",
"nouasprezece"
};
private static string[] _tens =
{
"",
"zece",
"douazeci",
"treizeci",
"patruzeci",
"cincizeci",
"saizeci",
"saptezeci",
"optzeci",
"nouazeci"
};
// US Nnumbering:
private static string[] _thousands =
{
"",
"mie",
"milion",
"miliard",
"trilion",
"catralion"
};
string digits, temp;
bool showThousands = false;
bool allZeros = true;
// Use StringBuilder to build result
StringBuilder builder = new StringBuilder();
// Convert integer portion of value to string
digits = ((long)value).ToString();
// Traverse characters in reverse order
for (int i = digits.Length - 1; i >= 0; i--)
{
int ndigit = (int)(digits[i] - '0');
int column = (digits.Length - (i + 1));
// Determine if ones, tens, or hundreds column
switch (column % 3)
{
case 0: // Ones position
showThousands = true;
if (i == 0)
{
// First digit in number (last in loop)
temp = String.Format("{0} ", _ones[ndigit]);
}
else if (digits[i - 1] == '1')
{
// This digit is part of "teen" value
temp = String.Format("{0} ", _teens[ndigit]);
// Skip tens position
i--;
}
else if (ndigit != 0)
{
// Any non-zero digit
temp = String.Format("{0} ", _ones[ndigit]);
}
else
{
// This digit is zero. If digit in tens and hundreds
// column are also zero, don't show "thousands"
temp = String.Empty;
// Test for non-zero digit in this grouping
if (digits[i - 1] != '0' || (i > 1 && digits[i - 2] != '0'))
showThousands = true;
else
showThousands = false;
}
// Show "thousands" if non-zero in grouping
if (showThousands)
{
if (column > 0)
{
temp = String.Format("{0}{1}{2}",
temp,
_thousands[column / 3],
allZeros ? " " : ", ");
}
// Indicate non-zero digit encountered
allZeros = false;
}
builder.Insert(0, temp);
break;
case 1: // Tens column
if (ndigit > 0)
{
temp = String.Format("{0}{1}",
_tens[ndigit],
(digits[i + 1] != '0') ? " si " : " ");
builder.Insert(0, temp);
}
break;
case 2: // Hundreds column
if (ndigit > 0)
{
temp = String.Format("{0} sute ", _ones[ndigit]);
builder.Insert(0, temp);
}
break;
}
}
builder.AppendFormat("lei si {0:00} bani", (value - (long)value) * 100);
// Capitalize first letter
return String.Format("{0}{1}",
Char.ToUpper(builder[0]),
builder.ToString(1, builder.Length - 1));
【问题讨论】:
-
sute 或 suta 是否只有 2 种可能性? (我问是因为在俄语中,还有更多;1 ticha;2 tichi;5 tisich;21 ticha)它变得复杂......
-
一百 = o suta,超过一百(两百等)你说 doua sute,一千 = o mie,两千 = doua mii 这就是我想要的。
标签: c# numbers decimal number-formatting