From c80facd63cd36fcee2a22ec562e75a86c7649db5 Mon Sep 17 00:00:00 2001 From: Ca-Phun Ung Date: Fri, 3 Oct 2008 04:08:08 +0000 Subject: [PATCH] Spinner: further refactored number formatter. 3 lines! --- ui/ui.spinner.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/ui/ui.spinner.js b/ui/ui.spinner.js index a99735f15..d0069b177 100644 --- a/ui/ui.spinner.js +++ b/ui/ui.spinner.js @@ -399,18 +399,9 @@ $.extend($.ui.spinner, { return (num !== Math.abs(num) ? '-' : '') + sym + this.number(Math.abs(num), 2); }, number: function(num, dec) { - num = isNaN(num) ? 0 : parseFloat(num,10).toFixed(dec); - - var regex = /(\d+)(\d{3})/, - n = num.toString().split('.'), - n1 = n[0], - n2 = n.length > 1 ? '.' + n[1] : ''; - - while (regex.test(n1)) { - n1 = n1.replace(regex, '$1,$2'); - } - - return (n1 + n2); + var regex = /(\d+)(\d{3})/; + for (num = isNaN(num) ? 0 : parseFloat(num,10).toFixed(dec); regex.test(num); num=num.replace(regex, '$1,$2')); + return num; } } });