HELP! HELP! HELP ME PLEASE >> i found this code and edit it but some bug about number
i call it like this
and this is fs function
and this is interger to word function
problem is if number is 4,846.03 it will convert to Four Thousand Eight hundred Forty Six and Three and it should be Four Thousand Eight hundred Forty Six and Zero Three ,right ?
please help!!!
i call it like this
C#:
double NetTotal = ((SubTotal-Advance)+TRate)+Vat;
lblNetTotal.Text = NetTotal.ToString("###,###,##0.00");
fs(NetTotal);
and this is fs function
C#:
public void fs(double allNum)
{
string firstNum=Convert.ToString(allNum);
ArrayList al = new ArrayList();
string[] parts = firstNum.Split('.');
al.InsertRange(0,parts);
int countArray = 0;
foreach(string a in al)
{
countArray +=1;
if (countArray==1)
{
double NetFirst = Convert.ToDouble(a);
lblToText.Text = IntegerToWords(NetFirst);
}
else
{
double NetSec = Convert.ToDouble(a);
lblToText.Text = lblToText.Text + " and " + IntegerToWords(NetSec);
}
}
}
C#:
public string IntegerToWords(double 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",
"Million",
"Billion",
"Trillion",
"Quadrillion",
"Quintillion"
};
bool isNegative=false;
if (inputNum<0)
{
isNegative=true;
inputNum*=-1;
}
if (inputNum==0)
return ("zero");
string s=inputNum.ToString();
while (s.Length>0)
{
// Get the three rightmost characters
x=(s.Length<3) ? s : s.Substring(s.Length - 3, 3);
// 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 nonzero
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
retval=tens[dig2] + " " + ones[dig3] + " " + retval;
}
// if a hundreds part is there, translate it
if (dig1>0)
retval = ones[dig1] + " hundred " + retval;
s=(s.Length - 3)>0 ? s.Substring(0,s.Length - 3) : "";
level++;
}
while (retval.IndexOf(" ")>0)
retval=retval.Replace(" "," ");
retval=retval.Trim();
if (isNegative)
retval="negative " + retval;
return (retval);
}
problem is if number is 4,846.03 it will convert to Four Thousand Eight hundred Forty Six and Three and it should be Four Thousand Eight hundred Forty Six and Zero Three ,right ?
please help!!!