write out number




JavaScript Source Code 3000: Equivalents: Write Out Number







































Write Out Number







This script takes a number and converts it to its English equivalent. If you enter 45678 in the number box and click the appropriate button, Forty Five Thousand Six Hundred Seventy Eight appears in the lower box.





Enter a number between 0 and 999,999,999 (No commas please.)




Number:



Text:












JavaScript Source Code 3000: Equivalents: Write Out Number
Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!





    





<!-- TWO STEPS TO INSTALL WRITE OUT NUMBER:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: jc491403@altavista.com -->

<! >
<! >

<!-- Begin
var n = "";
function validate(input) {
if (input.length == 0) {
alert ('Please Enter A Number.');
document.myform.textver.value = "";
return true;
}
else convert(input);
}
function d1(x) { // single digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= " One "; break;
case '2': n= " Two "; break;
case '3': n= " Three "; break;
case '4': n= " Four "; break;
case '5': n= " Five "; break;
case '6': n= " Six "; break;
case '7': n= " Seven "; break;
case '8': n= " Eight "; break;
case '9': n= " Nine "; break;
default: n = "Not a Number";
}
return n;
}
function d2(x) { // 10x digit terms
switch(x) {
case '0': n= ""; break;
case '1': n= ""; break;
case '2': n= " Twenty "; break;
case '3': n= " Thirty "; break;
case '4': n= " Forty "; break;
case '5': n= " Fifty "; break;
case '6': n= " Sixty "; break;
case '7': n= " Seventy "; break;
case '8': n= " Eighty "; break;
case '9': n= " Ninety "; break;
default: n = "Not a Number";
}
return n;
}
function d3(x) { // teen digit terms
switch(x) {
case '0': n= " Ten "; break;
case '1': n= " Eleven "; break;
case '2': n= " Twelve "; break;
case '3': n= " Thirteen "; break;
case '4': n= " Fourteen "; break;
case '5': n= " Fifteen "; break;
case '6': n= " Sixteen "; break;
case '7': n= " Seventeen "; break;
case '8': n= " Eighteen "; break;
case '9': n= " Nineteen "; break;
default: n= "Not a Number";
}
return n;
}
function convert(input) {
var inputlength = input.length;
var x = 0;
var teen1 = "";
var teen2 = "";
var teen3 = "";
var numName = "";
var invalidNum = "";
var a1 = ""; // for insertion of million, thousand, hundred
var a2 = "";
var a3 = "";
var a4 = "";
var a5 = "";
digit = new Array(inputlength); // stores output
for (i = 0; i < inputlength; i++) {
// puts digits into array
digit[inputlength - i] = input.charAt(i)};
store = new Array(9); // store output
for (i = 0; i < inputlength; i++) {
x= inputlength - i;
switch (x) { // assign text to each digit
case x=9: d1(digit[x]); store[x] = n; break;
case x=8: if (digit[x] == "1") {teen3 = "yes"}
else {teen3 = ""}; d2(digit[x]); store[x] = n; break;
case x=7: if (teen3 == "yes") {teen3 = ""; d3(digit[x])}
else {d1(digit[x])}; store[x] = n; break;
case x=6: d1(digit[x]); store[x] = n; break;
case x=5: if (digit[x] == "1") {teen2 = "yes"}
else {teen2 = ""}; d2(digit[x]); store[x] = n; break;
case x=4: if (teen2 == "yes") {teen2 = ""; d3(digit[x])}
else {d1(digit[x])}; store[x] = n; break;
case x=3: d1(digit[x]); store[x] = n; break;
case x=2: if (digit[x] == "1") {teen1 = "yes"}
else {teen1 = ""}; d2(digit[x]); store[x] = n; break;
case x=1: if (teen1 == "yes") {teen1 = "";d3(digit[x])}
else {d1(digit[x])}; store[x] = n; break;
}
if (store[x] == "Not a Number"){invalidNum = "yes"};
switch (inputlength){
case 1: store[2] = "";
case 2: store[3] = "";
case 3: store[4] = "";
case 4: store[5] = "";
case 5: store[6] = "";
case 6: store[7] = "";
case 7: store[8] = "";
case 8: store[9] = "";
}
if (store[9] != "") { a1 =" Hundred, "} else {a1 = ""};
if ((store[9] != "")||(store[8] != "")||(store[7] != ""))
{ a2 =" Million, "} else {a2 = ""};
if (store[6] != "") { a3 =" Hundred "} else {a3 = ""};
if ((store[6] != "")||(store[5] != "")||(store[4] != ""))
{ a4 =" Thousand, "} else {a4 = ""};
if (store[3] != "") { a5 =" Hundred "} else {a5 = ""};
}
// add up text, cancel if invalid input found
if (invalidNum == "yes"){numName = "Invalid Input"}
else {
numName = store[9] + a1 + store[8] + store[7]
+ a2 + store[6] + a3 + store[5] + store[4]
+ a4 + store[3] + a5 + store[2] + store[1];
}
store[1] = ""; store[2] = ""; store[3] = "";
store[4] = ""; store[5] = ""; store[6] = "";
store[7] = ""; store[8] = ""; store[9] = "";
if (numName == ""){numName = "Zero"};
document.myform.textver.value = numName;
return true;
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
Enter a number between 0 and 999,999,999 (No commas please.)

<form name="myform">
<table border=0>
<tr>
<td>Number:</td>
<td><input name="numver" size=9 maxlength=9> <input onclick="return validate(document.myform.numver.value)" type="button" value="Write Out Number"></td>
</tr>
<tr>
<td>Text:</td>
<td><input name="textver" size=50 maxlength=50></td>
</tr>
<tr>
<td align=middle colspan=2></td>
</tr>
</table>
</form>
</center>



<!-- Script Size: 4.95 KB -->










Wyszukiwarka

Podobne podstrony:
120320125306?c tewsc?t out?g
NumberAndDateFormatting csproj FileListAbsolute
docs Nebula Fix Numbers
NumberFormatProvider
function printer write
write
Regardie I Enochian Numbers
EC vocabulary numbers 0 20 E with KEY
Mystikal Smoked Out
NumberUp
[4x06] Prison Break Blow Out
L1 III Pol Normy okluzji hend out(1)
lights out

więcej podobnych podstron