根据数字大小返回中文数字、英文字母 /*数字转英文*/document.write(numToEn(3) + "\t");function numToEn(num) {var a = ["a", "b,", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", 'p', 'q', 'r', 's', 't', 'u
/*数字转英文*/
document.write(numToEn(3) + "\t");
function numToEn(num) {
var a = ["a", "b,", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
return a[num - 1];
}
/*数字转中文*/
document.write(numToWorld(3) + "\t");
document.write(numToWorld(20) + "\t");
document.write(numToWorld(11) + "\t");
function numToWorld(num) {
if(num < 10) {
return world(num);
} else {
let ten = Math.floor(num / 10);
let other = num % 10;
if(other == 0) {
return world(ten) + "十";
} else {
return world(ten) + "十" + world(other);
}
}
}
function world(x) {
if(x == 1) {
return "一";
}
if(x == 2) {
return "二";
}
if(x == 3) {
return "三";
}
if(x == 4) {
return "四";
}
if(x == 5) {
return "五";
}
if(x == 6) {
return "六";
}
if(x == 7) {
return "七";
}
if(x == 8) {
return "八";
}
if(x == 9) {
return "九";
}
}
