[查看演示] 源码如下 ---------------------------------------------------------- <html>
<head>
<title>Decimal Numbers Reader-www.51windows.Net</title>
<style>
<!--
body { font-family: Courier,Tahoma; font-size:12pt; font-color:black; background: background }
input { font-family: Courier,Tahoma; font-size:12pt; font-color:black }
div { font-family: Courier, Tahoma; font-size: 12pt; font-color: black; border: 1 double #FFFFFF; margin: 0; padding: 10 }
-->
</style>
</head>
<body>
<p>Decimal Numbers Reader by pauljs on 2002/05/12 22:00
<form name="num2En" onsubmit="readNum();return false">
<input name="realtime" id="realtime" type="checkbox" checked onclick="if(this.checked)readNum();else readout.innerHTML='结果输出:'"><label for="realtime">启用实时转换</label><br>
<input name="arabNum" type="text" size="50" maxlength="50" onpaste="return false" onkeyup="if(num2En.realtime.checked)readNum()" onkeypress="if(event.keyCode>57||event.keyCode<48&&event.keyCode!=13&&event.keyCode!=44&&event.keyCode!=46)event.returnValue=false;">
<input type="button" value="转换" onclick="readNum()" title="也可以直接按回车键执行!">
</form>
*可接受的输入:数字、","(逗号分隔符)和"."(小数点)
<p>
<div id="readout">结果输出:</div><br>
*按照美国英语习惯和《牛津高级英汉双解词典》采用的表达方式输出
<script>
A = "zero^one^two^three^four^five^six^seven^eight^nine^ten^eleven^twelve^thirteen^fourteen^fifteen^sixteen^seventeen^eighteen^nineteen^^twenty^thirty^forty^fifty^sixty^seventy^eighty^ninety^hundred^^thousand^million^billion^trillion^quadrillion^quintillion".split("^");
B = new Array();
for (i=0;i<1000;i++) {
B[i] = i<20?A[i]:i<100?A[19+Math.floor(i/10)]+(i%10==0?"":"-"+B[i%10]):A[Math.floor(i/100)]+" "+A[29]+(i%100==0?"":" and "+B[i%100]);
}
function readNum() {
text = "";
with (num2En.arabNum.value.split(".")[0].split(",").join("")) {
for (i=0;i<Math.ceil(length/3);i++) {
sec = parseInt(substring(length-3*i-3,length-3*i),10);
text = (i==0&&sec>0&&sec<100&&parseInt(substring(0,length-3),10)>0?" and ":"")+(sec==0&&(i>0||toString(10)!=0)?"":B[sec])+(sec==0?"":" "+(typeof A[30+i]=="undefined"?"undefined".fontcolor("red"):A[30+i]))+(i==0||sec==0||(sec>0&&text=="")?"":",".fontcolor("white")+" ")+text;
}
}
if (num2En.arabNum.value.indexOf(".")!=-1) {
with (num2En.arabNum.value.split(".")[1].split(",").join("")) {
for (i=0;i<length;i++) {
sec = parseInt(substring(i,i+1),10);
text += (i==0?(text==""?A[0]:"")+" point ".fontcolor("white"):"")+(sec==0&&i!=0&&!parseInt(substring(i+1),10)>0?"":B[sec]+" ");
}
}
}
return readout.innerHTML = (text.indexOf("undefined")==-1?"":typeof alert("数字超长,超出部分将无法正确输出!")=="undefined"&&num2En.arabNum.focus()?"":"")+"结果输出:<br>"+text;
}
</script>
<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div> |