金额转换为英文格式
请问金额2500要怎样才能设置才能显示成Two Thousand, Five Hundred Dollars Only关于您的问题:如何将金额使用英文展示
这个我们内置确实暂时不行,但是可以使用自定义脚本实现。脚本实现可以参考这个帖子:
https://help.grapecity.com.cn/pages/viewpage.action?pageId=5972510
我这边大概写了一个,您可以试一下:
public string ConvertNumberToWords(int number)
{
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[] thousands = new string[]
{
"", "Thousand", "Million", "Billion", "Trillion"
};
if (number == 0)
{
return "Zero";
}
string words = "";
if (number < 0)
{
words += "Negative ";
number = Math.Abs(number);
}
int index = 0;
do
{
// 取三位数
int num = number % 1000;
if (num != 0)
{
string word = "";
if (num >= 100)
{
int hundreds = num / 100;
word += $"{ones} Hundred ";
num %= 100;
}
if (num >= 20)
{
int tensDigit = num / 10;
word += $"{tens} ";
num %= 10;
}
if (num > 0)
{
word += ones;
}
string str = word.Trim();
words = $"{str} {thousands} {words}";
}
number /= 1000;
index++;
} while (number > 0);
return words.Trim()+ " Dollars Only";
}
我这边做了测试,目前展示正常:
页:
[1]