標籤:
//判斷月租金輸入是否是數字
function SetDefaultValueInError() {
var yzj = document.getElementById("ctl00_ContentPlaceHolder2_RadTextBox11_text");//擷取源
var tmpV = "";
if (yzj != null) {
tmpV = yzj.value;
if (isNaN(tmpV)) {
tmpV = 0;
}
}
document.getElementById("ctl00_ContentPlaceHolder2_RadTextBox11_text").value = tmpV;//設定控制項的值(小寫)
GetValueA(tmpV);
}
//擷取各個位上的數
function GetValueA(tmpV) {
var yjz = MoneyCn(parseFloat(tmpV));
var b, s, y, j;
var a = "佰";
var a1 = "拾";
var a2 = "圓";
var a3 = "角";
var a4 = "分";
b = yjz.toString().split(a.toString().split(‘‘)).length > 1 ? yjz.toString().split(a.toString().split(‘‘)) [0].substring(yjz.toString().split(a.toString().split(‘‘))[0].length - 1) : "零";
s = yjz.toString().split(a1.toString().split(‘‘)).length > 1 ? yjz.toString().split(a1.toString().split(‘‘)) [0].substring(yjz.toString().split(a1.toString().split(‘‘))[0].length - 1) : "零";
y = yjz.toString().split(a2.toString().split(‘‘)).length > 1 ? yjz.toString().split(a2.toString().split(‘‘)) [0].substring(yjz.toString().split(a2.toString().split(‘‘))[0].length - 1) : "零";
j = yjz.toString().split(a3.toString().split(‘‘)).length > 1 ? yjz.toString().split(a3.toString().split(‘‘)) [0].substring(yjz.toString().split(a3.toString().split(‘‘))[0].length - 1) : "零";
f = yjz.toString().split(a4.toString().split(‘‘)).length > 1 ? yjz.toString().split(a4.toString().split(‘‘)) [0].substring(yjz.toString().split(a4.toString().split(‘‘))[0].length - 1) : "零";
if (y == "拾" || y == "佰") {
y = "零";
}
if (y == "一") {
y = "壹";
}
//在這裡可以進行相應的賦值
.......
.......
}
//轉換大寫函數
function MoneyCn(number) {
if (number == 0) {
return "零";
}
var Result = ConvertNumberToCase(number);//轉換標準
//alert(Result);
Result = Result.toString().replace("一", "壹");
Result = Result.toString().replace("二", "貳");
Result = Result.toString().replace("三", "三");
Result = Result.toString().replace("四", "肆");
Result = Result.toString().replace("五", "伍");
Result = Result.toString().replace("六", "陸");
Result = Result.toString().replace("七", "柒");
Result = Result.toString().replace("八", "捌");
Result = Result.toString().replace("九", "玖");
Result = Result.toString().replace("九", "玖");
Result = Result.toString().replace("十", "拾");
Result = Result.toString().replace("百", "佰");
Result = Result.toString().replace("千", "仟");
//alert(Result);
Result = Result.toString().replace("一", "壹");
Result = Result.toString().replace("二", "貳");
Result = Result.toString().replace("三", "三");
Result = Result.toString().replace("四", "肆");
Result = Result.toString().replace("五", "伍");
Result = Result.toString().replace("六", "陸");
Result = Result.toString().replace("七", "柒");
Result = Result.toString().replace("八", "捌");
Result = Result.toString().replace("九", "玖");
Result = Result.toString().replace("九", "玖");
Result = Result.toString().replace("十", "拾");
Result = Result.toString().replace("百", "佰");
Result = Result.toString().replace("千", "仟");
Result = Result.toString().replace("一", "壹");
if (Result.toString().split("點") != null && Result.toString().split("點").length >= 2) {
var P = Result.toString().indexOf("點");
//Result = Result.toString().push(P + 2, "角");
Result = Result.toString().replace("點", "圓");
Result = Result.toString().replace("角分", "角");
Result = Result.toString().replace("零分", "");
Result = Result.toString().replace("零角", "");
Result = Result.toString().replace("分角", "");
if (Result.toString().substring(0, 2) == "零圓") {
Result = Result.Replace("零圓", "");
}
}
else {
Result += "圓整";
}
Result = "人民幣" + Result;
return Result;
}
//轉換大寫標準
function ConvertNumberToCase(number) {
var cPointCn = "點十百千萬十百千億十百千";
var cNumberCn = "零一二三四五六七八九";
if (number == "0") {
return "" + cPointCn.substring(0, 1);
}
if (number.toString().split(‘.‘) != null && number.toString().split(‘.‘).length < 2) {
number += ".";
}
var P = number.toString().indexOf(".");
var Result = "";
for (var i = 0; i < number.toString().length; i++) {
if (P == i) {
Result = Result.toString().replace("零十零", "零");
Result = Result.toString().replace("零百零", "零");
Result = Result.toString().replace("零千零", "零");
Result = Result.toString().replace("零十", "零");
Result = Result.toString().replace("零百", "零");
Result = Result.toString().replace("零千", "零");
Result = Result.toString().replace("零萬", "萬");
Result = Result.toString().replace("零億", "億");
Result = Result.toString().replace("億萬", "億");
Result = Result.toString().replace("零點", "點");
}else {
if (P > i) {
Result += "" + cNumberCn.substring(number.toString().substring(i, i + 1), parseInt(number.toString().substring(i, i + 1), 10) + 1) + cPointCn.substring(P - i - 1, P - i);
}
else {
var n = i - P;
switch (n) {
case 1:
Result += "" + cNumberCn.substring(number.toString().substring(i, i + 1), parseInt(number.toString().substring(i, i + 1), 10) + 1) + "角";
break;
case 2:
Result += "" + cNumberCn.substring(number.toString().substring(i, i + 1), parseInt(number.toString().substring(i, i + 1), 10) + 1) + "分";
break;
default:
Result += "" + cNumberCn.substring(number.toString().substring(i, i + 1), parseInt(number.toString().substring(i, i + 1), 10) + 1);
break;
}
Result = Result.toString().replace("零角", "角");
Result = Result.toString().replace("零分", "分");
}
}
}
if (Result.toString().substring(Result.toString().Length - 1, 1) == "" + cPointCn.substring(0,1)) {
Result = Result.toString().remove(Result.Length - 1); // 一點-> 一
}
if (Result.substring(0, 1) == cPointCn.substring(0, 1)) {
Result = cNumberCn.substring(0, 1) + Result; // 點三-> 零點三
}
if ((Result.toString().Length > 1) && (Result.substring(1, 2) == cPointCn.substring(1, 2)) && (Result.substring(0, 1) == cNumberCn.substring(1, 2))) {
Result = Result.toString().remove(0, 1); // 一十三-> 十三
}
//alert(Result);
return Result;
}
使用js進行數字大小寫轉換