我怎样才能将整数转换的言语再presentation? [英] How can I convert an integer into its verbal representation?
本文介绍了我怎样才能将整数转换的言语再presentation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个库或类/功能,我可以用一个整数转换成它的语言重新presentation?
Is there a library or a class/function that I can use to convert an integer to it's verbal representation?
例输入: 4567788
输出示例: 400万,五百67000,788
有关的参考,我使用C#和.NET 3.5。
For reference, I am using C# and .NET 3.5.
推荐答案
如果您使用code发现: 转换的号码字C# 你需要它的十进制数字,这里是如何做到这一点:
if you use the code found in: converting numbers in to words C# and you need it for decimal numbers, here is how to do it:
public string DecimalToWords(decimal number)
{
if (number == 0)
return "zero";
if (number < 0)
return "minus " + DecimalToWords(Math.Abs(number));
string words = "";
int intPortion = (int)number;
decimal fraction = (number - intPortion)*100;
int decPortion = (int)fraction;
words = NumericToWords(intPortion);
if (decPortion > 0)
{
words += " and ";
words += NumericToWords(decPortion);
}
return words;
}
这篇关于我怎样才能将整数转换的言语再presentation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文