将价格数字转换为字母格式 [英] Convert the price digits to alphabetic format
本文介绍了将价格数字转换为字母格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
转换为以数字表示的价格,即金额转换为字母样式
例如 100到一百美元 或其他货币
任何清晰的代码或想法?
in asp.net(c#) i want to convert the price written in digits i.e. the amount to an alphabetic style
for example 100 to one hundred dollar or to what ever currency
Any clear code or ideas??
推荐答案
hiii,
将对象定义为
textBox1.text = 100
hiii,
Define Object as
textBox1.text=100
AmountInWords obj=new AmountInWords();
textbox2.Text=obj.ConvertAmount(Convert.ToDouble(textBox1.Text))
输出为一百
类文件在哪里
AmountInWords.cs
And Output is= One Hundred
where class file is
AmountInWords.cs
class AmountInWords
{
private static String[] units = { "Zero", "One", "Two", "Three",
"Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
"Seventeen", "Eighteen", "Nineteen" };
private static String[] tens = { "", "", "Twenty", "Thirty", "Forty",
"Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
public String ConvertAmount(double amount)
{
try
{
int amount_int = (int)amount;
int amount_dec = (int)Math.Round((amount - (double)(amount_int)) * 100);
return convert(amount_int) + " point "
+ convert(amount_dec);
}
catch (Exception e)
{
// TODO: handle exception
}
return "";
}
public String convert(int i)
{
//
if (i < 20)
return units[i];
if (i < 100)
return tens[i / 10] + ((i % 10 > 0) ? " " + convert(i % 10) : "");
if (i < 1000)
return units[i / 100] + " Hundred"
+ ((i % 100 > 0) ? " and " + convert(i % 100) : "");
if (i < 100000)
return convert(i / 1000) + " Thousand "
+ ((i % 1000 > 0) ? " " + convert(i % 1000) : "");
if (i < 10000000)
return convert(i / 100000) + " Lakh "
+ ((i % 100000 > 0) ? " " + convert(i % 100000) : "");
return convert(i / 10000000) + " Crore "
+ ((i % 10000000 > 0) ? " " + convert(i % 10000000) : "");
}
}
尝试以下链接
asp.net中单词的数字 [
Hi,
Try following link
Numbers to words in asp.net[^]
您好,
试试这个.
http://forums.asp.net/t/1367362.aspx/1 [ ^ ]
-Milind
Hi,
Try this.
http://forums.asp.net/t/1367362.aspx/1[^]
-Milind
这篇关于将价格数字转换为字母格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文