Re: number to text function
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Thu, 8 Mar 2007 00:10:15 -0600
"aa" <A@xxxxxx> wrote in message
news:eCuYFBOYHHA.984@xxxxxxxxxxxxxxxxxxxxxxx
Is there an off-the shelf available function which would accept a numberand
returns it as text like 15 returns "fifteen"?
Since you specified "numbers" not "dollars",
the following works for 0 through 999,999.
For example, 999,999 is converted to:
Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
You may want the result in all lowercase...
Watch for word-wrap.
var AMT = "123,456";
WScript.Echo(AMT + " = " + Amount(AMT));
function Amount(AMT) {
var strAMT = AMT.replace(/,/,"");
if (isNaN(strAMT)) {
WScript.Echo("Invalid number! " + strAMT);
return;
}
if (parseInt(strAMT,10) < 0 || parseInt(strAMT,10) > 999999) {
WScript.Echo("Invalid amount! " + strAMT);
return;
}
var intAMT = parseInt(strAMT,10) + 1000000;
strAMT = intAMT + "";
var intMOD;
var arrNOS = new Array();
arrNOS[1] = "One";
arrNOS[2] = "Two";
arrNOS[3] = "Three";
arrNOS[4] = "Four";
arrNOS[5] = "Five";
arrNOS[6] = "Six";
arrNOS[7] = "Seven";
arrNOS[8] = "Eight";
arrNOS[9] = "Nine";
arrNOS[10] = "Ten";
arrNOS[11] = "Eleven";
arrNOS[12] = "Twelve";
arrNOS[13] = "Thirteen";
arrNOS[14] = "Fourteen";
arrNOS[15] = "Fifteen";
arrNOS[16] = "Sixteen";
arrNOS[17] = "Seventeen";
arrNOS[18] = "Eighteen";
arrNOS[19] = "Nineteen";
arrNOS[20] = "Twenty";
arrNOS[30] = "Thirty";
arrNOS[40] = "Forty";
arrNOS[50] = "Fifty";
arrNOS[60] = "Sixty";
arrNOS[70] = "Seventy";
arrNOS[80] = "Eighty";
arrNOS[90] = "Ninety";
var intNOS
var strVAL = "";
intNOS = strAMT.substr(5,2);
if (intNOS != 0) {
intMOD = intNOS % 10;
if (intNOS <= 20 || intMOD == 0) {
strVAL = arrNOS[intNOS];
} else {
strVAL = arrNOS[intNOS-intMOD] + " " + arrNOS[intMOD];
}
}
intNOS = strAMT.substr(4,1);
if (intNOS != 0) {
strVAL = arrNOS[intNOS] + " Hundred " + strVAL;
}
intNOS = strAMT.substr(2,2);
if (intNOS != 0) {
intMOD = intNOS % 10;
if (intNOS <= 20 || intMOD == 0) {
strVAL = arrNOS[intNOS] + " Thousand " + strVAL;
} else {
strVAL = arrNOS[intNOS-intMOD] + " " + arrNOS[intMOD] + "
Thousand " + strVAL;
}
}
intNOS = strAMT.substr(1,1);
if (intNOS != 0) {
strVAL = arrNOS[intNOS] + " Hundred " + strVAL;
}
return strVAL;
}
.
- Follow-Ups:
- Re: number to text function
- From: aa
- Re: number to text function
- From: Dr J R Stockton
- Re: number to text function
- References:
- number to text function
- From: aa
- number to text function
- Prev by Date: Re: how to debug a javascript?
- Next by Date: Display Data in Client side
- Previous by thread: Re: number to text function
- Next by thread: Re: number to text function
- Index(es):
Loading