Number to Word - Indian Currency Format

  • Thread starter Syed Ali Abjimiah
  • Start date
S

Syed Ali Abjimiah

Dear All

I would like to Print the Number to Text ... Examble

If cell contains the value of : 5,11,22,000.55 : convert to " 5 Crore , 11
Lakhs , 22 Thousand . 55 Paisa "

Pls Help

Regards

Syed
 
A

Althaf Hussain

currency to word indian format by Althaf
-------------------------------------------------------

public string IntegerToWords(long inputNum)
{
int dig1, dig2, dig3, level = 0, lasttwo, threeDigits;
string retval = "";
string x = "";
string[] ones ={
"Zero",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Eleven ",
"Twelve ",
"Thirteen ",
"Fourteen ",
"Fifteen ",
"Sixteen ",
"Seventeen ",
"Eighteen ",
"Nineteen "
};
string[] tens ={
" Zero ",
" Ten ",
" Twenty ",
" Thirty ",
" Forty ",
" Fifty ",
" Sixty ",
" Seventy ",
" Eighty ",
" Ninety "
};
string[] thou ={
"",
"Thousand",
"Lakh",
"Crore",
"Trillion",
"Quadrillion",
"Quintillion"
};
bool isNegative = false;
if (inputNum < 0)
{
isNegative = true;
inputNum *= -1;
}
if (inputNum == 0)
return ("Zero");

string s = inputNum.ToString();
int i = 3;
while (s.Length > 0)
{
// Get the three rightmost characters
x = (s.Length < i) ? s : s.Substring(s.Length - i, i);

// Separate the three digits
threeDigits = int.Parse(x);
lasttwo = threeDigits % 100;
dig1 = threeDigits / 100;
dig2 = lasttwo / 10;
dig3 = (threeDigits % 10);

// append a "thousand" where appropriate
if (level > 0 && dig1 + dig2 + dig3 > 0)
{
retval = thou[level] + " " + retval;
retval = retval.Trim();
}
// check that the last two digits is not a zero
if (lasttwo > 0)
{
if (lasttwo < 20) // if less than 20, use "ones" only
retval = ones[lasttwo] + " " + retval;
else // otherwise, use both "tens" and "ones" array
if (ones[dig3].ToString() != "Zero")
{
retval = tens[dig2] + " " + ones[dig3] + " " + retval;
}
else
{
retval = tens[dig2] + " " + retval;
}
}
// if a hundreds part is there, translate it
if (dig1 > 0 && level == 0)
retval = ones[dig1] + " Hundred " + " and " + retval;
s = (s.Length - i) > 0 ? s.Substring(0, s.Length - i) : "";
level++;
i = 2;
}

while (retval.IndexOf(" ") > 0)
retval = retval.Replace(" ", " ");

retval = retval.Trim()+" only";

if (isNegative)
retval = "negative " + retval;

return (retval);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top