<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=0; i < n.length; i++)
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> /-------------------------2016.2.25修改-------------------------------------
//请款金额校验 function upperAccount(loweramount){ if(loweramount!=''&&loweramount!=0){ //有两位小数的正实数 var reg = new RegExp("^[0-9]+(.[0-9]{2})?$"); if(loweramount.indexOf(",")!=-1){ loweramount=loweramount.replace(/,/g,'');//12322.12格式化之前的 if(!reg.test(loweramount)){ alert("请输入正确金额,最多两位小数!"); return; } }; //小写 var v = fmoney(loweramount); $("#money").val(v);//123,22.12格式化之后的 //大写 if(v.indexOf(",")!=-1){ v=v.replace(/,/g,'');//12322.12格式化之前的 }; $("input[name='currentApplyAmount']").val(v); var upper = DX(v); $("input[name='upper_currentApplyAmount']").val(upper); }else{ $("#money").val(0.0); $("input[name='currentApplyAmount']").val('0.0'); $("input[name='upper_currentApplyAmount']").val('零'); } } //将请款金额转大写 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=0; i < n.length; i++) 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, "元整"); } /** * 将数值四舍五入后格式化. * * @param s 数值(Number或者String) * @param n 要保留的小数位(Number) * @return 格式的字符串,如'1,234,567.45' * @type String */ function fmoney(s, n){ n = n > 0 && n <= 20 ? n : 2; s = parseFloat((s + "").replace(/[^d.-]/g, "")).toFixed(n) + ""; var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1]; t = ""; for(i = 0; i < l.length; i ++ ) { t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : ""); } return t.split("").reverse().join("") + "." + r; }
<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=0; i < n.length; i++)
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=0; i < n.length; i++)
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>
/-------------------------2016.2.25修改-------------------------------------
//请款金额校验
function upperAccount(loweramount){
if(loweramount!=''&&loweramount!=0){
//有两位小数的正实数
var reg = new RegExp("^[0-9]+(.[0-9]{2})?$");
if(loweramount.indexOf(",")!=-1){
loweramount=loweramount.replace(/,/g,'');//12322.12格式化之前的
if(!reg.test(loweramount)){
alert("请输入正确金额,最多两位小数!");
return;
}
};
//小写
var v = fmoney(loweramount);
$("#money").val(v);//123,22.12格式化之后的
//大写
if(v.indexOf(",")!=-1){
v=v.replace(/,/g,'');//12322.12格式化之前的
};
$("input[name='currentApplyAmount']").val(v);
var upper = DX(v);
$("input[name='upper_currentApplyAmount']").val(upper);
}else{
$("#money").val(0.0);
$("input[name='currentApplyAmount']").val('0.0');
$("input[name='upper_currentApplyAmount']").val('零');
}
}
//将请款金额转大写
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=0; i < n.length; i++)
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, "元整");
}
/**
* 将数值四舍五入后格式化.
*
* @param s 数值(Number或者String)
* @param n 要保留的小数位(Number)
* @return 格式的字符串,如'1,234,567.45'
* @type String
*/
function fmoney(s, n){
n = n > 0 && n <= 20 ? n : 2;
s = parseFloat((s + "").replace(/[^d.-]/g, "")).toFixed(n) + "";
var l = s.split(".")[0].split("").reverse(),
r = s.split(".")[1];
t = "";
for(i = 0; i < l.length; i ++ )
{
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").reverse().join("") + "." + r;
}