I'm looking for a library that can take a number such as 1,000,000,000
and output a partial text represenation e.g. 1 billion
- but (preferably) in an already localised manner. (So that if the culture was not english we'd get the appropriate text representation.)
我正在寻找一个图书馆,它可以接收10亿这样的数字,并输出部分文本,例如10亿,但是(最好)以一种已经本地化的方式输出。(因此,如果文化不是英语,我们就会得到适当的文本表示。)
Does such a thing exist?
这种东西存在吗?
It should be able to do
它应该能够做到。
1,000,000 -> 1 million
56,243,152 -> 56 million
I know I'm asking a lot - but it would be a pain to have to re-invent something to do this.
我知道我提出了很多要求——但要想做这件事,必须重新发明一些东西,这将是一件痛苦的事。
1 个解决方案
#1
6
Here are a few links you may find interesting:
以下是一些有趣的链接:
- http://www.blackwasp.co.uk/NumberToWords.aspx
- http://www.blackwasp.co.uk/NumberToWords.aspx
- http://midnightprogrammer.net/post/Convert-Numbers-to-Words-in-C.aspx
- http://midnightprogrammer.net/post/Convert-Numbers-to-Words-in-C.aspx
- http://www.c-sharpcorner.com/UploadFile/b942f9/6362/
- http://www.c-sharpcorner.com/UploadFile/b942f9/6362/
You'll find that these are algorithms that people have created themselves. This is because OSs and frameworks that provide localization/internationalization have to do so within reason. That is, providing translations for well-known and limited subsets of data such as months names, names of the days of the week and simple formatting characters such as currency symbols.
你会发现这些是人们自己创造的算法。这是因为提供本地化/国际化的OSs和框架必须在合理的范围内这么做。也就是说,为众所周知的、有限的数据子集提供翻译,如月份名称、星期名称和简单的格式化字符(如货币符号)。
What you are asking for is a step past these services and requires a specific dictionary. When internationalizing/localizing an application this is typically done in the app via different resource files that provide dictionaries in supported languages that relate to that particular application.
您需要的是超越这些服务的一步,并需要一个特定的字典。国际化/本地化应用程序时,通常是通过不同的资源文件在应用程序中完成的,这些文件以与特定应用程序相关的受支持语言提供字典。
I would suggest analyzing the source code from the two links above to see if it meets your needs, at least closely. Then create a language-agnostic version of the algorithm that can accept a dictionary of numeric terms that can change on-the-fly.
我建议从上面的两个链接中分析源代码,看看它是否满足您的需求,至少是紧密的。然后创建一个与语言无关的算法版本,它可以接受一个可以动态变化的数字词汇字典。
#1
6
Here are a few links you may find interesting:
以下是一些有趣的链接:
- http://www.blackwasp.co.uk/NumberToWords.aspx
- http://www.blackwasp.co.uk/NumberToWords.aspx
- http://midnightprogrammer.net/post/Convert-Numbers-to-Words-in-C.aspx
- http://midnightprogrammer.net/post/Convert-Numbers-to-Words-in-C.aspx
- http://www.c-sharpcorner.com/UploadFile/b942f9/6362/
- http://www.c-sharpcorner.com/UploadFile/b942f9/6362/
You'll find that these are algorithms that people have created themselves. This is because OSs and frameworks that provide localization/internationalization have to do so within reason. That is, providing translations for well-known and limited subsets of data such as months names, names of the days of the week and simple formatting characters such as currency symbols.
你会发现这些是人们自己创造的算法。这是因为提供本地化/国际化的OSs和框架必须在合理的范围内这么做。也就是说,为众所周知的、有限的数据子集提供翻译,如月份名称、星期名称和简单的格式化字符(如货币符号)。
What you are asking for is a step past these services and requires a specific dictionary. When internationalizing/localizing an application this is typically done in the app via different resource files that provide dictionaries in supported languages that relate to that particular application.
您需要的是超越这些服务的一步,并需要一个特定的字典。国际化/本地化应用程序时,通常是通过不同的资源文件在应用程序中完成的,这些文件以与特定应用程序相关的受支持语言提供字典。
I would suggest analyzing the source code from the two links above to see if it meets your needs, at least closely. Then create a language-agnostic version of the algorithm that can accept a dictionary of numeric terms that can change on-the-fly.
我建议从上面的两个链接中分析源代码,看看它是否满足您的需求,至少是紧密的。然后创建一个与语言无关的算法版本,它可以接受一个可以动态变化的数字词汇字典。