ExtJS4.2数字转换大写在提示框显示

//人民币金额转大写程序 JavaScript版     
//CopyRight Bardo QI     
    
function numToCny(num){     
    var capUnit = ['万','亿','万','圆',''];     
    var capDigit = { 2:['角','分',''], 4:['仟','佰','拾','']};     
    var capNum=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'];     
    if (((num.toString()).indexOf('.') > 16)||(isNaN(num)))      
        return '';     
    num = ((Math.round(num*100)).toString()).split('.');  
	num = (num[0]).substring(0, (num[0]).length-2)+'.'+ (num[0]).substring((num[0]).length-2,(num[0]).length);  
    num =((Math.pow(10,19-num.length)).toString()).substring(1)+num;     
    var i,ret,j,nodeNum,k,subret,len,subChr,CurChr=[];     
    for (i=0,ret='';i<5;i++,j=i*4+Math.floor(i/4)){     
        nodeNum=num.substring(j,j+4);     
        for(k=0,subret='',len=nodeNum.length;((k<len) && (parseInt(nodeNum.substring(k),10)!=0));k++){     
            CurChr[k%2] = capNum[nodeNum.charAt(k)]+((nodeNum.charAt(k)==0)?'':capDigit[len][k]);     
            if (!((CurChr[0]==CurChr[1]) && (CurChr[0]==capNum[0])))     
                if(!((CurChr[k%2] == capNum[0]) && (subret=='') && (ret=='')))     
                    subret += CurChr[k%2];     
        }     
        subChr = subret + ((subret=='')?'':capUnit[i]);     
        if(!((subChr == capNum[0]) && (ret=='')))     
            ret += subChr;     
    }     
    ret=(ret=='')? capNum[0]+capUnit[3]: ret;       
    return ret;     
}   



{
			        fieldLabel: 'checkword',
			        name: 'checkword',
			        //tipTpl: Ext.create('Ext.XTemplate', '<ul class="' + Ext.plainListCls + '"><tpl for="."><li><span class="field-name">{name}</span>: <span class="error">{error}</span></li></tpl></ul>'),
			        getTip: function() {
	                    var tip = this.tip;
	                    if (!tip) {
	                        tip = this.tip = Ext.widget('tooltip', {
	                            target: this.el,
	                            minWidth: 200,
	                            autoHide: false,
	                            anchor: 'top',
	                            //closable: true,
	                            mouseOffset: [-11, -2],
	                            constrainPosition: false
	                        });
	                        tip.show();
	                    }
	                    return tip;
	                },
	                listeners: {
				        change: {
				            fn: function(t, newValue, oldValue, eOpts){
					            var tip = this.getTip();
				            	if(t.getValue() != null && t.getValue() != ''){
					            	tip.update('小写:' + t.getValue());
	                        		tip.setTitle('大写:' + numToCny(t.getValue()));
	                        		tip.show();
                        		}else{
                        			tip.setDisabled(true);
                        			tip.hide();
                        		}
							}
				        }
				    },
			        allowBlank: false
			    }







发布了52 篇原创文章 · 获赞 12 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/caodegao/article/details/8866913
今日推荐