Convert number to amount in words

Time:2021-6-9

Convert number to amount in words

About more daily use of public class operation method, you can pay attention to the next small website http://www.feiaci.com/#/self/…

/**
 *Convert number to amount in words
 */
function changeToChinese (Num) {
    //Judge if the input is not a character, then convert it to a character
    if(typeof Num == "number") {
        Num = new String(Num);
    };
    Num = num.replace (/, / g, ") // replace", "in tomoney()
    Num = num.replace (// g, ") // replace the space in tomoney()
    Num = num.replace (/ ¥ / g, ") // replace the possible ¥ character
    If (IsNaN (Num)) {// verify that the input character is a number
        //Alert ("please check whether the amount in figures is correct");
        return "";
    };
    //After the character is processed, the conversion is started, and the two parts are converted separately
    let part = String(Num).split(".");
    let newchar = "";
    //Conversion before decimal point
    for(let i = part[0].length - 1; i >= 0; i--) {
        if(part[0].length > 10) {
            return "";
            //If the quantity exceeds one billion units, prompt
        }
        let tmpnewchar = ""
        let perchar = part[0].charAt(i);
        switch(perchar) {
            case "0":
                Tmpnewchar = "zero" + tmpnewchar;
                break;
            case "1":
                Tmpnewchar = "one" + tmpnewchar;
                break;
            case "2":
                Tmpnewchar = "two" + tmpnewchar;
                break;
            case "3":
                Tmpnewchar = "three" + tmpnewchar;
                break;
            case "4":
                Tmpnewchar = "four" + tmpnewchar;
                break;
            case "5":
                Tmpnewchar = "+ tmpnewchar;
                break;
            case "6":
                Tmpnewchar = "Lu" + tmpnewchar;
                break;
            case "7":
                Tmpnewchar = "7" + tmpnewchar;
                break;
            case "8":
                Tmpnewchar = "eight" + tmpnewchar;
                break;
            case "9":
                Tmpnewchar = "Nine" + tmpnewchar;
                break;
        }
        switch(part[0].length - i - 1) {
            case 0:
                Tmpnewchar = tmpnewchar + "meta";
                break;
            case 1:
                if(perchar !=  0) tmpnewchar = tmpnewchar + "pick up";
                break;
            case 2:
                if(perchar !=  0) tmpnewchar = tmpnewchar + "hundred";
                break;
            case 3:
                if(perchar !=  0) tmpnewchar = tmpnewchar + "thousand";
                break;
            case 4:
                Tmpnewchar = tmpnewchar + ten thousand;
                break;
            case 5:
                if(perchar !=  0) tmpnewchar = tmpnewchar + "pick up";
                break;
            case 6:
                if(perchar !=  0) tmpnewchar = tmpnewchar + "hundred";
                break;
            case 7:
                if(perchar !=  0) tmpnewchar = tmpnewchar + "thousand";
                break;
            case 8:
                Tmpnewchar = tmpnewchar + 100 million;
                break;
            case 9:
                Tmpnewchar = tmpnewchar + "pick up";
                break;
        }
        let newchar = tmpnewchar + newchar;
    }
    //Conversion after decimal point
    if(Num.indexOf(".") != -1) {
        if(part[1].length > 2) {
            //Alert ("only two decimal places can be reserved after the decimal point, and the system will automatically truncate");
            part[1] = part[1].substr(0, 2)
        }
        for(i = 0; i < part[1].length; i++) {
            tmpnewchar = ""
            perchar = part[1].charAt(i)
            switch(perchar) {
                case "0":
                    Tmpnewchar = "zero" + tmpnewchar;
                    break;
                case "1":
                    Tmpnewchar = "one" + tmpnewchar;
                    break;
                case "2":
                    Tmpnewchar = "two" + tmpnewchar;
                    break;
                case "3":
                    Tmpnewchar = "three" + tmpnewchar;
                    break;
                case "4":
                    Tmpnewchar = "four" + tmpnewchar;
                    break;
                case "5":
                    Tmpnewchar = "+ tmpnewchar;
                    break;
                case "6":
                    Tmpnewchar = "Lu" + tmpnewchar;
                    break;
                case "7":
                    Tmpnewchar = "7" + tmpnewchar;
                    break;
                case "8":
                    Tmpnewchar = "eight" + tmpnewchar;
                    break;
                case "9":
                    Tmpnewchar = "Nine" + tmpnewchar;
                    break;
            }
            If (I = = 0) tmpnewchar = tmpnewchar + angle;
            If (I = = 1) tmpnewchar = tmpnewchar + "points";
            newchar = newchar + tmpnewchar;
        }
    }
    //Replace all useless Chinese characters
    While (newchar. Search ("zero")! = 0- 1)
        Newchar = newchar. Replace ("zero", "zero");
    Newchar = newchar. Replace ("0 billion", "100 million");
    Newchar = newchar. Replace ("billion", "billion");
    Newchar = newchar. Replace ("ten thousand", "ten thousand");
    Newchar = newchar. Replace ("zero yuan", "Yuan");
    Newchar = newchar. Replace ("zero angle", ");
    Newchar = newchar. Replace ("zero", ");
    If (newchar. Charat (newchar. Length - 1) = = = yuan){
        Newchar = newchar + "integer"
    }
    return newchar;
}

Recommended Today

Rust programming video tutorial (Advanced) – 024_ 3 syntax of all modes 3

Video address Headline address:https://www.ixigua.com/i677586170644791348…Station B address:https://www.bilibili.com/video/av81202308/ Source address GitHub address:https://github.com/anonymousGiga/learn_rus… Explanation content 1. Ignore values in mode(1) Use_ Ignore entire valueexample: fn foo(_: i32, y: i32) { println!(“This code only uses the y parameter: {}”, y); } fn main() { foo(3, 4); } Note: placeholders are used for parameters in the function, mainly when implementing […]