5

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.

Massif
  • 4,327
  • 23
  • 25
  • 1
    It looks like a similar question has been asked before: http://stackoverflow.com/questions/554314/how-can-i-convert-an-integer-into-its-verbal-representation I don't think any of the responses factored in localization though. Hopefully it at least gives you a head start. – Giovanni Galbo Nov 03 '11 at 13:14
  • 2
    This is a shopping question and not suitable for SE. Somebody will have an answer and you'll dismiss it because it doesn't happen to support a particular language you need. http://blog.stackoverflow.com/2010/11/qa-is-hard-lets-go-shopping/ – Hans Passant Nov 03 '11 at 13:36

1 Answers1

6

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.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189