Roo/util/Format.js
authorAlan Knowles <alan@roojs.com>
Tue, 31 Jul 2012 04:04:09 +0000 (12:04 +0800)
committerAlan Knowles <alan@roojs.com>
Tue, 31 Jul 2012 04:04:09 +0000 (12:04 +0800)
Roo/util/Format.js

index b961390..40435f7 100644 (file)
@@ -172,17 +172,29 @@ Roo.util.Format = function(){
          * @param {Number/String} value The numeric value to format
          * @return {String} The formatted currency string
          */
-        number : function(v){
-            v = (Math.round((v-0)*100))/100;
+        number : function(v,decimals)
+        {
+            // multiply and round.
+            decimals = typeof(decimals) == 'undefined' ? 2 : decimals
+            var mul = Math.pow(10, decimals);
+            
+            v = (Math.round((v-0)*mul))/mul;
+            
             v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
             v = String(v);
             var ps = v.split('.');
             var whole = ps[0];
-            var sub = ps[1] ? '.'+ ps[1] : '.00';
+            
+            
             var r = /(\d+)(\d{3})/;
+            // add comma's
             while (r.test(whole)) {
                 whole = whole.replace(r, '$1' + ',' + '$2');
             }
+            
+            var sub = ps[1] ? '.'+ ps[1] : '.00';
+            
+            
             return whole + sub ;
         },