• 常用的一些函


    //判断数据类型的方法
    let arr= [1,2,3]
    function
    getDataType(args) { let cc= Object.prototype.toString.call(args) // [object ...] return '数据类型是:'+ cc.replace(/^[object (S+)]$/, '$1'); } console.log(getDataType(arr))
    //金额大小写转换
    function convertCurrency (currencyDigits) {
                    var MAXIMUM_NUMBER = 1000000000000.0;
    
                    var CN_ZERO = '零';
                    var CN_ONE = '壹';
                    var CN_TWO = '贰';
                    var CN_THREE = '叁';
                    var CN_FOUR = '肆';
                    var CN_FIVE = '伍';
                    var CN_SIX = '陆';
                    var CN_SEVEN = '柒';
                    var CN_EIGHT = '捌';
                    var CN_NINE = '玖';
                    var CN_TEN = '拾';
                    var CN_HUNDRED = '佰';
                    var CN_THOUSAND = '仟';
                    var CN_TEN_THOUSAND = '万';
                    var CN_HUNDRED_MILLION = '亿';
                    var CN_SYMBOL = '人民币';
                    var CN_DOLLAR = '元';
                    var CN_TEN_CENT = '角';
                    var CN_CENT = '分';
                    var CN_INTEGER = '整';
    
                    var integral; // integral part
                    var decimal; // decimal part
                    var outputCharacters = ''; // result.
                    var parts;
                    var digits, radices, bigRadices, decimals;
                    var zeroCount;
                    var i, p, d;
                    var quotient, modulus;
    
                    if (currencyDigits != null) {
                        currencyDigits = currencyDigits.toString();
                        currencyDigits = currencyDigits.replace(/,/g, ''); // Remove comma delimiters.
                        currencyDigits = currencyDigits.replace(/^0+/, ''); // Trim zeros at the beginning.
    
                        if (Number(currencyDigits) < MAXIMUM_NUMBER) {
                            if (Number(currencyDigits) < 0) {
                                outputCharacters += '负';
                                currencyDigits = Math.abs(Number(currencyDigits)).toString();
                            }
    
                            parts = currencyDigits.split('.'); // separate the number by decimal point
                            if (parts.length > 1) {
                                integral = parts[0];
                                decimal = parts[1];
                                decimal = decimal.substr(0, 2); // two decimal places
                            } else {
                                integral = parts[0];
                                decimal = '';
                            }
    
                            digits = new Array(
                                CN_ZERO,
                                CN_ONE,
                                CN_TWO,
                                CN_THREE,
                                CN_FOUR,
                                CN_FIVE,
                                CN_SIX,
                                CN_SEVEN,
                                CN_EIGHT,
                                CN_NINE
                            );
                            radices = new Array('', CN_TEN, CN_HUNDRED, CN_THOUSAND);
                            bigRadices = new Array('', CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
                            decimals = new Array(CN_TEN_CENT, CN_CENT);
    
                            if (Number(integral) > 0) {
                                zeroCount = 0;
                                for (i = 0; i < integral.length; i++) {
                                    p = integral.length - i - 1;
                                    d = integral.substr(i, 1);
                                    quotient = p / 4;
                                    modulus = p % 4;
                                    if (d == '0') {
                                        zeroCount++;
                                    } else {
                                        if (zeroCount > 0) {
                                            outputCharacters += digits[0];
                                        }
                                        zeroCount = 0;
                                        outputCharacters += digits[Number(d)] + radices[modulus];
                                    }
                                    if (modulus == 0 && zeroCount < 4) {
                                        outputCharacters += bigRadices[quotient];
                                    }
                                }
                                outputCharacters += CN_DOLLAR;
                            }
    
                            if (decimal != '') {
                                for (i = 0; i < decimal.length; i++) {
                                    d = decimal.substr(i, 1);
                                    if (d != '0') {
                                        outputCharacters += digits[Number(d)] + decimals[i];
                                    }
                                }
                            }
                            if (outputCharacters == '') {
                                outputCharacters = CN_ZERO + CN_DOLLAR;
                            }
                            if (decimal == '') {
                                outputCharacters += CN_INTEGER;
                            }
                            outputCharacters = '' + outputCharacters + '';
                        }
                    }
                    return outputCharacters;
                };
    // 格式化金钱 每三位进用逗号隔开(银行金钱格式)
    function outputcents (amount) {
        amount = Math.round(((amount) - Math.floor(amount)) * 100);
        return (amount < 10 ? '.0' + amount : '.' + amount);
    };
    
    function outputdollars (number) {
        if (number.length <= 3)
            return (number == '' ? '0' : number);
        else {
            var mod = number.length % 3;
            var output = (mod == 0 ? '' : (number.substring(0, mod)));
            for (var i = 0; i < Math.floor(number.length / 3); i++) {
                if ((mod == 0) && (i == 0))
                    output += number.substring(mod + 3 * i, mod + 3 * i + 3);
                else
                    output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
            }
            return (output);
        }
    };
    
     function outputmoney (number) {
        // number = number.toString().replace(/\,/g, "");
        number = number.toString().replace(/\,/g, "");
        if (isNaN(number) || number == "") return "";
        number = Math.round(number * 100) / 100;
        if (number < 0)
            return '-' + outputdollars(Math.floor(Math.abs(number) - 0) + '') + outputcents(Math.abs(number) - 0);
        else
            return outputdollars(Math.floor(number - 0) + '') + outputcents(number - 0);
    };
    console.log(outputmoney(15698763)) // 15,698,763.00
            // 随机数生成函数区间
                function randomNumber (startNum, endNum) {
                    if (startNum.constructor !== Number || endNum.constructor !== Number) {
                        alert('您输入的范围区间数据数据类型不正确!')
                        return false
                    }
    
                    return Math.floor(Math.random() * (endNum - startNum) + startNum)
                }
  • 相关阅读:
    图像分割学习笔记_1(opencv自带meanshift分割例子)
    基础学习笔记之opencv(10):Mat mask操作
    Qt学习之路_6(Qt局域网聊天软件)
    Qt学习之路_8(Qt中与文件目录相关操作)
    Android开发历程_6(RadioButton和CheckBox的使用)
    Qt学习之路_4(Qt UDP的初步使用)
    目标跟踪学习笔记_4(particle filter初探3)
    Reading papers_11(读Integrating local action elements for action analysis相关文章)
    基础学习笔记之opencv(8):Mat 基本图像容器
    基础学习笔记之opencv(14):随机数发生器&绘制文字
  • 原文地址:https://www.cnblogs.com/lxsunny/p/13738357.html
Copyright © 2020-2023  润新知