<script language="JavaScript">
function daxie()
{
this.values = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
this.digits = ["", "拾", "佰", "仟"];
}
function daxie.prototype.getdx(num)
{
if(isNaN(num)) return "";
var number = Math.round(num*100)/100;
number = number.toString(10).split('.');
var integer = number[0];
var len = integer.length;
if (len > 12)
return "数值超出范围!支持的最大数值为 999999999999.99";
var returnValue = this.bns(integer.slice(-4));
if (len > 4)
returnValue = this.bns(integer.slice(-8,-4)) + (integer.slice(-8,-4)!="0000"?"万":"") + returnValue;
if (len > 8)
returnValue = this.bns(integer.slice(-12,-8)) + "亿" + returnValue;
if(returnValue!="")
returnValue += "圆";
if(number.length==2)
{
var cok = number[1].split('');
if(returnValue!="" || cok[0]!="0")
returnValue += this.values[parseInt(cok[0])] + (cok[0]!="0"?"角":"");
if(cok.length>=2)
returnValue += this.values[parseInt(cok[1])] + "分";
}
if(returnValue!="" && !/分$/.test(returnValue))
returnValue += "整";
return returnValue;
}
function daxie.prototype.bns(str)
{
var num = str.split('');
var dsl = num.length-1;
var returnValue = "";
for (var i=0; i<=dsl; i++)
returnValue += this.values[parseInt(num[i])] + (num[i]!='0'?this.digits[dsl-i]:"");
returnValue = returnValue.replace(/零+$/, "").replace(/零{2,}/, "零");
return returnValue;
}
//
var stmp = "";
var dfs = new daxie();
function nst(t)
{
if(t.value==stmp) return;
var ms = t.value.replace(/[^/d/.]/g,"").replace(/(/./d{2}).+$/,"$1");
var txt = ms.split(".");
while(//d{4}(,|$)/.test(txt[0]))
txt[0] = txt[0].replace(/(/d)(/d{3}(,|$))/,"$1,$2");
t.value = stmp = txt[0]+(txt.length>1?"."+txt[1]:"");
bbb.value = dfs.getdx(parseFloat(ms));
}
</script>
小写金额:<input type="text" name="aaa" οnkeyup="nst(this)"><br>
大写金额:<input type="text" name="bbb" size=60 readonly>