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.)
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.
Here are a few links you may find interesting:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With