Is there an easy way to convert a number to Indian words format with lakhs and crores?
As the title suggests I would like to convert a long number to the format with words using C#. The Culture settings don't seem to do this and I am just currently doing this
String.Format(new CultureInfo("en-IN"), "{0:C0}", Price)
But for very long numbers I would prefer the word format. I am not from 开发者_运维问答India and only vaguely familiar with how the system works.
public static string NumberToWords(int number)
{
if (number == 0) { return "zero"; }
if (number < 0) { return "minus " + NumberToWords(Math.Abs(number)); }
string words = "";
if ((number / 10000000) > 0) { words += NumberToWords(number / 10000000) + " Crore "; number %= 10000000; }
if ((number / 100000) > 0) { words += NumberToWords(number / 100000) + " Lakh "; number %= 100000; }
if ((number / 1000) > 0) { words += NumberToWords(number / 1000) + " Thousand "; number %= 1000; }
if ((number / 100) > 0) { words += NumberToWords(number / 100) + " Hundred "; number %= 100; }
if (number > 0)
{
if (words != "") { words += "and "; }
var unitsMap = new[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
var tensMap = new[] { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "seventy", "Eighty", "Ninety" };
if (number < 20) { words += unitsMap[number]; }
else { words += tensMap[number / 10]; if ((number % 10) > 0) { words += "-" + unitsMap[number % 10]; } }
}
return words;
}
- 1 - One
- 10 - Ten
- 1000 - Thousand
- 10,000 - Ten Thousand
- 1,00,000 - Lakh
- 10,00,000 - Ten Lakh
- 1,00,00,000 - Crore
- 10,00,00,000 - Ten Crore
.. after this, Arab, Kharab, Neel etc are NOT in conventional use. Infact, even financial institutions follow this:
- 100,00,00,000 - Hundred Crore
- 1,000,00,00,000 - One Thousand Crore
- 10,000,00,00,000 - Ten Thousand Crore
- 1,00,000,00,00,000 - One Lakh Crore (Trillion)
- 99,00,000,00,00,000 - Ninety-nine Lakh Crore (Trillion)
Once this number has been exceeded, they conveniently switch to millions/billions/trillions/quadrillions..
While I can't give you the code itself, here's the system
- 1 - One
- 10 - Ten
- 1000 - Thousand
- 10000 - Ten Thousand
- 100000 - Lakh
- 1000000 - Ten Lakh
- 10000000 - Crore
- 100000000 - Ten Crore
- 1000000000 - Arab
- 10000000000 - Ten Arab
- 100000000000 - Kharab
- 1000000000000 - Ten Kharab
- 10000000000000 - 1 Neel
- 100000000000000 - 10 Neel
- 1000000000000000 - 1 Padm
I had written the routines for an accounting package I made, so writing it is not particularly hard.
You can use 'Srilibs.NumberToText.Netstandard' library into your project. This is easiest way to convert any number to Indian currency in words.
精彩评论