var num = parseFloat(str)
var strOutput = "",
strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分'
num += "00"
var intPos = num.indexOf('.')
if (intPos >= 0){
num = num.substring(0, intPos) + num.substr(intPos + 1, 2)
}
strUnit = strUnit.substr(strUnit.length - num.length)
for (var i=0i <num.lengthi++){
strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(num.substr(i,1),1) + strUnit.substr(i,1)
}
return strOutput.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元")
}
<script type="text/javascript">//主函数
function DX(n) {
if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
return "数据非法"
var unit = "千百拾亿千百拾万千百拾元角分", str = ""
n += "00"
var p = n.indexOf('.')
if (p >= 0)
n = n.substring(0, p) + n.substr(p+1, 2)
unit = unit.substr(unit.length - n.length)
for (var i=0i <n.lengthi++)
str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i)
return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整")
}
//以下为测试输出
alert('1526365.56 '+DX(1526365.56))
</script>
function DX(n) {if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(n))
return "数据非法"
var unit = "千百拾亿千百拾万千百拾元角分", str = ""
n += "00"
var p = n.indexOf('.')
if (p >= 0)
n = n.substring(0, p) + n.substr(p+1, 2)
unit = unit.substr(unit.length - n.length)
for (var i=0i <n.lengthi++)
str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i)
return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元整")
}