• 金额 千分位分隔 指定小数位数


     //////////////////数字千分符 
    function rendererZhMoney(v,l) {  
                if(isNaN(v)){  
                    return v;
                    //v=0;  
                }  
                
                if(l == undefined) l = 2;
                //v = (Math.round((v - 0) * 1000)) / 1000;
                 v = (Math.round((v - 0) * Math.pow(10,l))) / Math.pow(10,l);   
               //v = (v == Math.floor(v)) ? v + ".000" : ((v * 10 == Math.floor(v * 10)) ? v  
               //         + "00" : (v * 100 == Math.floor(v * 100)) ? v  
               //         + "0" : v); 
               v = addZero(v,l);
                v = String(v);  
                var ps = v.split('.');  
                var whole = ps[0];  
               // var sub = ps[1] ? '.' + ps[1] : '.000';
                 var sub = ps[1] ? '.' + ps[1] : addZero2(l);    
                var r = /(d+)(d{3})/;  
                while (r.test(whole)) {  
    //                whole = whole.replace(r, '$1' + ',' + '$2',+'$3','$4','$5','$6');  
                    whole = whole.replace(r, '$1' + ',' + '$2'); 
                }  
                v = whole + sub;  
                  
                return v;  
            }
            
    function addZero(v,l){
        for(var i=0;i<l;i++){
            if(v * Math.pow(10,i) == Math.floor(v * Math.pow(10,i))){
                if(i==0) v=v+".";
                for(var j=0;j<l-i;j++){
                    v = v + "0";
                }
                return v;
            }
        }
        return v;
    }
    
    function addZero2(l){
        var s=".";
        for(var i=0;i<l;i++){
            s= s+"0";
        }
        return s;
    }
        
             
    Ext.ux.NuberFiledFormat=Ext.extend(Ext.form.NumberField, {   
              baseChars: "0123456789,",   
                setValue: function(v){   
               v = typeof v == 'number' ? v : String(v).replace(this.decimalSeparator, ".").replace(/,/g, "");   
                v = isNaN(v) ? '' : rendererZhMoney(v);   
                  
               //Ext.util.Format.number(this.fixPrecision(String(v)), "0,000,000.00");此为ext 4.0    
                   this.setRawValue(v);   
                 return Ext.form.NumberField.superclass.setValue.call(this, v);   
            },   
             /* getValue:function(){  
                //alert((String(Ext.form.NumberField.superclass.getValue.call(this)).replace(",","")));  
                return (String(Ext.form.NumberField.superclass.getValue.call(this)).replace(",",""));  
              },  
               */  
              fixPrecision: function(value){   
                var nan = isNaN(value);   
                if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {   
                    return nan ? '' : value;   
                }   
                return parseFloat(value).toFixed(this.decimalPrecision);   
            },   
            validateValue: function(value){   
                if (!Ext.form.NumberField.superclass.validateValue.call(this, value)) {   
                    return false;   
                }   
                if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid   
                    return true;   
                }   
                value = String(value).replace(this.decimalSeparator, ".").replace(/,/g, "");   
                if (isNaN(value)) {   
                    this.markInvalid(String.format(this.nanText, value));   
                    return false;   
                }   
                var num = this.parseValue(value);   
                if (num < this.minValue) {   
                    this.markInvalid(String.format(this.minText, this.minValue));   
                    return false;   
                }   
                if (num > this.maxValue) {   
                    this.markInvalid(String.format(this.maxText, this.maxValue));   
                    return false;   
                }   
                return true;   
            },   
            parseValue: function(value){   
                value = parseFloat(String(value).replace(this.decimalSeparator, ".").replace(/,/g, ""));   
                return isNaN(value) ? '' : value;   
            }   
           }); 
  • 相关阅读:
    SCP 命令
    Android 系统默认参数的修改
    java类加载时机与过程
    Git学习总结四(删除)
    Git学习总结三(工作区和暂存区、撤销修改)
    Git学习总结二(版本回退)(git resrt / git revert / git checkout)
    Git学习总结一(下载、初始化、添加文件)
    Mybatis逆向工程使用方法
    Mybatis与Spring整合方法
    Mybatis学习总结四(关联查询)
  • 原文地址:https://www.cnblogs.com/mingforyou/p/3344532.html
Copyright © 2020-2023  润新知