• 价格单位换算方法


    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元"
    

      

  • 相关阅读:
    新闻资讯APP开发流程(一)需求分析
    药品查询APP开发流程(九)开发—yao_company.js
    药品查询APP开发流程(十一)开发—company_specs.js
    开发demo药品查询
    药品查询APP开发流程(十)开发—company.js
    药品查询APP开发流程(八)开发—yao_specs.js
    开发demo新闻资讯
    新闻资讯APP开发流程(三) app.js
    新闻资讯APP开发流程(二) APP模型设计
    药品查询APP开发流程(七)开发—yao.js
  • 原文地址:https://www.cnblogs.com/taochengyong/p/12131725.html
Copyright © 2020-2023  润新知