jsは数字を大文字に変換する人民元表現.

7169 ワード

function changeNumMoneyToChinese(money) {

    var cnNums = new Array(" ", " ", " ", " ", " ", " ", " ", " ", " ", " "); //     

    var cnIntRadice = new Array("", " ", " ", " "); //    

    var cnIntUnits = new Array("", " ", " ", " "); //          

    var cnDecUnits = new Array(" ", " ", " ", " "); //        

    var cnInteger = " "; //           

    var cnIntLast = " "; //        

    var maxNum = 999999999999999.9999; //       

    var IntegerNum; //      

    var DecimalNum; //      

    var ChineseStr = ""; //          

    var parts; //

    if (money == "") {

        return "";

    }

    money = parseFloat(money);

    if (money >= maxNum) {

        alert('        ');

        return "";

    }

    if (money == 0) {

        ChineseStr = cnNums[0] + cnIntLast + cnInteger;

        return ChineseStr;

    }

    money = money.toString(); //      

    if (money.indexOf(".") == -1) {

        IntegerNum = money;

        DecimalNum = '';

    } else {

        parts = money.split(".");

        IntegerNum = parts[0];

        DecimalNum = parts[1].substr(0, 4);

    }

    if (parseInt(IntegerNum, 10) > 0) { //        

        var zeroCount = 0;

        var IntLen = IntegerNum.length;

        for (var i = 0; i < IntLen; i++) {

            var n = IntegerNum.substr(i, 1);

            var p = IntLen - i - 1;

            var q = p / 4;

            var m = p % 4;

            if (n == "0") {

                zeroCount++;

            } else {

                if (zeroCount > 0) {

                    ChineseStr += cnNums[0];

                }

                zeroCount = 0; //  

                ChineseStr += cnNums[parseInt(n)] + cnIntRadice[m];

            }

            if (m == 0 && zeroCount < 4) {

                ChineseStr += cnIntUnits[q];

            }

        }

        ChineseStr += cnIntLast;

        //        

    }

    if (DecimalNum != '') { //    

        var decLen = DecimalNum.length;

        for (var i = 0; i < decLen; i++) {

            var n = DecimalNum.substr(i, 1);

            if (n != '0') {

                ChineseStr += cnNums[Number(n)] + cnDecUnits[i];

            }

        }

    }

    if (ChineseStr == '') {

        ChineseStr += cnNums[0] + cnIntLast + cnInteger;

    } else if (DecimalNum == '') {

        ChineseStr += cnInteger;

    }

    return ChineseStr;



}