/*******************************************
* 金额转换大写
*******************************************/
function showChinaValue(val) {
var totalValue = val;
var minusFlag = false;
if (totalValue < 0) {
minusFlag = true;
totalValue = Math.abs(totalValue);
}
var numberValue = new String(Math.round(totalValue * 100)); // 数字金额
var chineseValue = ""; // 转换后的汉字金额
if (minusFlag) {
chineseValue = "负 ";//负数
}
//var String1 = Lang["kmCmReimburseMain.patten.chinese"]; // 汉字数字
var String1 = '<bean:message key="kmCmReimburseMain.patten.chinese" bundle="fssc-loan"/>';
//alert(String1)
//var String2 = Lang["kmCmReimburseMain.patten.unit"]; // 对应单位
var String2 = '<bean:message key="kmCmReimburseMain.patten.unit" bundle="fssc-loan"/>'; // 对应单位
var len = numberValue.length; // numberValue 的字符串长度
var Ch1; // 数字的汉语读法
var Ch2; // 数字位的汉字读法
var nZero = 0; // 用来计算连续的零值的个数
var String3; // 指定位置的数值
if (len > 15) {
alert('<bean:message key="kmCmReimburseMain.patten.warn" bundle="fssc-loan"/>');
//alert(Lang["kmCmReimburseMain.patten.warn"]);
return "";
}
if (numberValue == 0) {
//chineseValue = Lang["kmCmReimburseMain.patten.init"];
chineseValue = '<bean:message key="kmCmReimburseMain.patten.init" bundle="fssc-loan"/>';
return chineseValue;
}
String2 = String2.substr(String2.length - len, len); // 取出对应位数的STRING2的值
for (var i = 0; i < len; i++) {
String3 = parseInt(numberValue.substr(i, 1), 10); // 取出需转换的某一位的值
if (i != (len - 3) && i != (len - 7) && i != (len - 11)
&& i != (len - 15)) {
if (String3 == 0) {
Ch1 = "";
Ch2 = "";
nZero = nZero + 1;
} else if (String3 != 0 && nZero != 0) {
//Ch1 = Lang["kmCmReimburseMain.patten.zero"]
Ch1 = '<bean:message key="kmCmReimburseMain.patten.zero" bundle="fssc-loan"/>'
+ String1.substr(String3, 1);
Ch2 = String2.substr(i, 1);
nZero = 0;
} else {
Ch1 = String1.substr(String3, 1);
Ch2 = String2.substr(i, 1);
nZero = 0;
}
} else { // 该位是万亿,亿,万,元位等关键位
if (String3 != 0 && nZero != 0) {
//Ch1 = Lang["kmCmReimburseMain.patten.zero"]
Ch1 = '<bean:message key="kmCmReimburseMain.patten.zero" bundle="fssc-loan"/>'
+ String1.substr(String3, 1);
Ch2 = String2.substr(i, 1);
nZero = 0;
} else if (String3 != 0 && nZero == 0) {
Ch1 = String1.substr(String3, 1);
Ch2 = String2.substr(i, 1);
nZero = 0;
} else if (String3 == 0 && nZero >= 3) {
Ch1 = "";
Ch2 = "";
nZero = nZero + 1;
} else {
Ch1 = "";
Ch2 = String2.substr(i, 1);
nZero = nZero + 1;
}
if (i == (len - 11) || i == (len - 3)) { // 如果该位是亿位或元位,则必须写上
Ch2 = String2.substr(i, 1);
}
}
chineseValue = chineseValue + Ch1 + Ch2;
}
var String4 = 0;
if (len > 2) {
String4 = parseInt(numberValue.substr(len - 2, 1), 10);
}
if (String3 == 0 && String4 == 0) { // 最后一位(分)为0时,加上“整”
chineseValue = chineseValue
+ '<bean:message key="kmCmReimburseMain.patten.zheng" bundle="fssc-loan"/>';
//+ Lang["kmCmReimburseMain.patten.zheng"];
}
return chineseValue;
}
调用
showChinaValue(‘1.0’)