Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a .NET library for formatting large numbers as text? [closed]

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.

like image 207
Massif Avatar asked Nov 03 '11 13:11

Massif


1 Answers

Here are a few links you may find interesting:

  • http://www.blackwasp.co.uk/NumberToWords.aspx
  • http://midnightprogrammer.net/post/Convert-Numbers-to-Words-in-C.aspx
  • 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.

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.

like image 163
Paul Sasik Avatar answered Nov 02 '22 04:11

Paul Sasik