• 价格单位换算方法


    function price (val,types, isNoUnpin, customModel) {
        let type = types
                    if(!val || isNaN(Number(val))) {
                        if (isNoUnpin) return type ? '0':'0.00'
                        else return type ? '0万元':'0.00元'
                    }
                    else {
                        if (customModel && Number(val) > 9999) type = true
                        let numb = type ? parseFloat((Number(val)/10000).toFixed(2)) : Number(val).toFixed(2)
                            ,str = numb.toString()
                            ,arr = str.split('.')
                            ,num0 = ''
                            ,re = /(?=(?!)(d{3})+$)/g
                        num0 = arr[0]
                        if(num0.length>3){
                            num0 = num0.replace(re, ',')
                        }
                        let unpin = type ? '万元' : '元'
                        if (isNoUnpin) unpin = ''
                        return num0 + (arr[1] ? '.'+arr[1]: '')+ unpin
                    }
    }
    price(100, false, false, true)
    
    "100.00元"
    function price (val,types, isNoUnpin, customModel) {
        let type = types
                    if(!val || isNaN(Number(val))) {
                        if (isNoUnpin) return type ? '0':'0.00'
                        else return type ? '0万元':'0.00元'
                    }
                    else {
                        if (customModel && Number(val) > 9999) type = true
                        let numb = type ? parseFloat((Number(val)/10000).toFixed(2)) : Number(val).toFixed(2)
                            ,str = numb.toString()
                            ,arr = str.split('.')
                            ,num0 = ''
                            ,re = /(?=(?!)(d{3})+$)/g
                        num0 = arr[0]
                        if(num0.length>3){
                            num0 = num0.replace(re, ',')
                        }
                        let unpin = type ? '万元' : '元'
                        if (isNoUnpin) unpin = ''
                        return num0 + (arr[1] ? '.'+arr[1]: '')+ unpin
                    }
    }
    price(10000, false, false, true)
    
    "1万元"
    function price (val,types, isNoUnpin, customModel) {
        let type = types
                    if(!val || isNaN(Number(val))) {
                        if (isNoUnpin) return type ? '0':'0.00'
                        else return type ? '0万元':'0.00元'
                    }
                    else {
                        if (customModel && Number(val) > 9999) type = true
                        let numb = type ? parseFloat((Number(val)/10000).toFixed(2)) : Number(val).toFixed(2)
                            ,str = numb.toString()
                            ,arr = str.split('.')
                            ,num0 = ''
                            ,re = /(?=(?!)(d{3})+$)/g
                        num0 = arr[0]
                        if(num0.length>3){
                            num0 = num0.replace(re, ',')
                        }
                        let unpin = type ? '万元' : '元'
                        if (isNoUnpin) unpin = ''
                        return num0 + (arr[1] ? '.'+arr[1]: '')+ unpin
                    }
    }
    price(10000, false, false)
    
    "10,000.00元"
    function price (val,types, isNoUnpin, customModel) {
        let type = types
                    if(!val || isNaN(Number(val))) {
                        if (isNoUnpin) return type ? '0':'0.00'
                        else return type ? '0万元':'0.00元'
                    }
                    else {
                        if (customModel && Number(val) > 9999) type = true
                        let numb = type ? parseFloat((Number(val)/10000).toFixed(2)) : Number(val).toFixed(2)
                            ,str = numb.toString()
                            ,arr = str.split('.')
                            ,num0 = ''
                            ,re = /(?=(?!)(d{3})+$)/g
                        num0 = arr[0]
                        if(num0.length>3){
                            num0 = num0.replace(re, ',')
                        }
                        let unpin = type ? '万元' : '元'
                        if (isNoUnpin) unpin = ''
                        return num0 + (arr[1] ? '.'+arr[1]: '')+ unpin
                    }
    }
    price(100, false, false)
    
    "100.00元"
    

      

  • 相关阅读:
    Java学习-060-Springboot
    PySe-013-指定安装源安装模块 + 修改安装源
    Linux-016-Centos Shell 遍历文本信息,通过流水号批量获取日志信息并保存结果
    Linux-015-Centos mysql 创建用户、数据库、授权、建表、数据插入
    Linux-014-Centos 开放端口 3306
    Linux-013-Centos mysql 5.6.50 修改字符集为 utf8
    Linux-012-Centos mysql 5.6.50 忘记密码,重置密码
    Linux-011-Centos 使用 yum 安装 mysql 5.6.50
    Linux-010-Centos 使用 yum 安装 pip
    Linux-009-Centos 安装 YUM
  • 原文地址:https://www.cnblogs.com/taochengyong/p/12131725.html
Copyright © 2020-2023  润新知