[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 /* 2 DynAPI Distribution 3 dynapi.functions.Numeric extension 4 */ 5 6 var f = dynapi.functions; 7 f.Numeric = Numeric = {}; // used by dynapi.library 8 9 // Numeric Function --------------------------------- 10 11 f.formatNumber = function(n,format){ 12 if(isNaN(n)) return; 13 var i,c,f,comma,symbol='',sign='',decimals='',integers=''; 14 var fInt,fDec,nInt,nDec,len=0,cnt=0; 15 if(n<0) sign='-'; 16 n+='';if(sign) n=n.replace('-',''); 17 format=(format)? format+'':'#,##0.00'; 18 if(format.indexOf(',')>=0) comma=','; 19 if(format.indexOf('$')>=0) symbol='$'; 20 else if(format.indexOf('%')>=0) symbol='%'; 21 s=format.split('.'); 22 fInt=((s[0]==''||s[0]==null||s[0]=='undefinded')? '':s[0]); 23 fInt=fInt.split('').reverse().join(''); 24 fDec=(s[1]==''||s[1]==null||s[1]=='undefinded')? '':s[1]; 25 s=n.split('.'); 26 nInt=((s[0]==''||s[0]==null||s[0]=='undefinded')? '':s[0]); 27 nInt=nInt.split('').reverse().join('');; 28 nDec=(s[1]==''||s[1]==null||s[1]=='undefinded')? '':s[1]; 29 if (nInt) len=nInt.length; 30 if (fInt.length>len) len=fInt.length; 31 for(i=0;i<len;i++){ 32 c=nInt.charAt(i); 33 f=fInt.charAt(i); 34 cnt++; 35 if (cnt==4 && comma && (c||f=='0')) integers+=comma; 36 if(f=='0' && !c) integers+='0'; 37 else if(c) integers+=c; 38 if (cnt==4) cnt=1; 39 } 40 if(fDec) len=fDec.length; 41 for(i=0;i<len;i++){ 42 c=nDec.charAt(i); 43 f=fDec.charAt(i); 44 if(f=='0' && !c) decimals+='0'; 45 else if((f=='#' || f=='0') && c) decimals+=c; 46 } 47 f=((integers+'').split('').reverse().join(''))+((decimals)? '.'+decimals:''); 48 if(symbol=='%') f+=symbol; 49 else f=symbol+f; 50 return sign+f; 51 }; 52 f.isFloat=function(n){ 53 if(typeof(n)=='number' && (n+'').indexOf('.')>=0) return true; 54 else return false; 55 }; 56 f.isInteger=function(n){ 57 if(typeof(n)=='number' && (n+'').indexOf('.')<0) return true; 58 else return false;; 59 }; 60 f.toInteger=function(dt){ 61 var vl; 62 if(!dt) return 0; 63 if(isNaN(dt)) vl=parseInt((dt+'').replace(/\,/g,'')); 64 else vl= parseInt(dt); 65 if (isNaN(vl)) vl = 0; 66 return vl; 67 }; 68 f.toFloat=function(dt){ 69 var vl; 70 if(!dt) return 0; 71 if(isNaN(dt)) vl=parseFloat((dt+'').replace(/\,/g,'')); 72 else vl = parseFloat(dt); 73 if (isNaN(vl)) vl = 0; 74 return vl; 75 }; 76 f.toBoolean = function(dt) { 77 return (dt=='true'||dt>=1)? true:false; 78 }; 79 80 f.isNumeric = function (n) 81 { 82 var nReg = new RegExp('[-][[:digit:]]'); 83 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |