private void button3_Click_1(object sender, EventArgs e)
{
textBox2.Text = "$" + (textBox1.Text = string.Format(System.Globalization.CultureInfo.GetCultureInfo("us-US"), "{0:#,##0.00}", double.Parse(textBox1.Text)));
string digits, temp;
long numberVal;
string[] powers = new string[] { "Thousand ", "Million " };
string[] ones = new string[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
string[] tens = new string[] { "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
string[] currency = new string[] { "Dollars" };
string wordValue = "";
if (numberVal == 0)
return "Nol";
if (numberVal < 0)
{
wordValue = "negative ";
numberVal = -numberVal;
}
long[] partStack = new long[] { 0, 0, 0, 0 };
int partNdx = 0;
while (numberVal > 0)
{
partStack[partNdx++] = numberVal % 1000;
numberVal /= 1000;
}
for (int i = 3; i >= 0; i--)
{
long part = partStack[i];
if (part >= 100)
{
wordValue += ones[part / 100 - 1] + " Ratus ";
part %= 100;
}
if (part >= 20)
{
if ((part % 10) != 0) wordValue += tens[part / 10 - 2] +
" " + ones[part % 10 - 1] + " ";
else wordValue += tens[part / 10 - 2] + " ";
}
else if (part > 0) wordValue += ones[part - 1] + " ";
if (part != 0 && i > 0) wordValue += powers[i - 1];
}
textBox3.Text = return wordValue;
}
我正在尝试将 long 类型的数字转换为字符串单词。
为什么我的函数返回错误,是我使用不正确还是其他原因?