28,376
社区成员




function ToCn(a) {
var b = 9.999999999999E10,
f = "零",
h = "壹",
g = "贰",
e = "叁",
k = "肆",
p = "伍",
q = "陆",
r = "柒",
s = "捌",
t = "玖",
l = "拾",
d = "佰",
i = "仟",
m = "万",
j = "亿",
u = "",
o = "元",
c = "角",
n = "分",
v = "整";
if (a == "") {
alert("请输入数字!");
return ""
}
if (a.match(/[^,.\d]/) != null) {
alert("请不要输入其他字符!");
return ""
}
if (a.match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) ==
null) {
alert("非法格式!");
return ""
}
a = a.replace(/,/g, "");
a = a.replace(/^0+/, "");
if (Number(a) > b) {
alert("对不起,你输入的数字太大了!最大数字为99999999999.99!");
return ""
}
b = a.split(".");
if (b.length > 1) {
a = b[0];
b = b[1];
b = b.substr(0, 2)
} else {
a = b[0];
b = ""
}
h = new Array(f, h, g, e, k, p, q, r, s, t);
l = new Array("", l, d, i);
m = new Array("", m, j);
n = new Array(c, n);
c = "";
if (Number(a) > 0) {
for (d = j = 0; d < a.length; d++) {
e = a.length - d - 1;
i = a.substr(d,
1);
g = e / 4;
e = e % 4;
if (i == "0") j++;
else {
if (j > 0) c += h[0];
j = 0;
c += h[Number(i)] + l[e]
}
if (e == 0 && j < 4) c += m[g]
}
c += o
}
if (b != "") for (d = 0; d < b.length; d++) {
i = b.substr(d, 1);
if (i != "0") c += h[Number(i)] + n[d]
}
if (c == "") c = f + o;
if (b.length < 2) c += v;
return c = u + c
}
var arr1 = new Array("", " thousand", " million", " billion"),
arr2 = new Array("zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"),
arr3 = new Array("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"),
arr4 = new Array("ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen");
function ToEn(a) {
var b = a.length,
f,
h = 0,
g = "",
e = Math.ceil(b / 3),
k = b - e * 3;
g = "";
for (f = k; f < b; f += 3) {
++h;
num3 = f >= 0 ? a.substring(f, f + 3) : a.substring(0, k + 3);
strEng = English(num3);
if (strEng != "") {
if (g != "") g += ",";
g += English(num3) + arr1[e - h]
}
}
return g
}
function English(a) {
strRet = "";
if (a.length == 3 && a.substr(0, 3) != "000") {
if (a.substr(0, 1) != "0") {
strRet += arr3[a.substr(0, 1)] + " hundred";
if (a.substr(1, 2) != "00") strRet += " and "
}
a = a.substring(1)
}
if (a.length == 2) if (a.substr(0, 1) == "0") a = a.substring(1);
else if (a.substr(0, 1) == "1") strRet += arr4[a.substr(1, 2)];
else {
strRet += arr2[a.substr(0, 1)];
if (a.substr(1, 1) != "0") strRet += "-";
a = a.substring(1)
}
if (a.length == 1 && a.substr(0, 1) != "0") strRet += arr3[a.substr(0, 1)];
return strRet
};
function copy(a) {
if (a = findObj(a)) {
a.select();
js = a.createTextRange();
js.execCommand("Copy")
}
}
function findObj(a, b) {
var c,
d;
b || (b = document);
if ((c = a.indexOf("?")) > 0 && parent.frames.length) {
b = parent.frames[a.substring(c + 1)].document;
a = a.substring(0, c)
}
if (!(d = b[a]) && b.all) d = b.all[a];
for (c = 0; !d && c < b.forms.length; c++) d = b.forms[c][a];
for (c = 0; !d && b.layers && c < b.layers.length; c++) d = findObj(a, b.layers[c].document);
if (!d && document.getElementById) d = document.getElementById(a);
return d
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script src="JS/DecodeNo.js" type="text/javascript"></script>
<script type="text/javascript">
function TransCn() {
document.getElementById("out").value = ToCn(document.getElementById("Num").value);
}
function TransEn() {
document.getElementById("out").value = ToEn(document.getElementById("Num").value);
}
</script>
<script type="text/javascript">
function AlertMessage() {
alert(document.getElementById("Num").value);
}
</script>
</head>
<body>
<form action="" method="get" name="mainForm">
<input type="text" name="Num" value="" id="Num" />
<div>
<input type="button" name="Eng" value="转换成英文 " onclick="TransEn()" />
<input type="button" name="Chinese" value="转换成中文 " onclick="TransCn()" />
</div>
<textarea name="out" cols="90" rows="5" id="out"></textarea>
<input type="button" name="alertMessage" value="Alert Message " onclick="AlertMessage();" />
</form>
</body>
</html>