Extended number formatting to allow use maximum precision for 'max' specification.
[fa-stable.git] / js / utils.js
index 8d707b3dd01682212d6add3644cc0e21f4dfa690..1f1aa521c54a362d31b98326e7971a55022ced13 100644 (file)
@@ -212,14 +212,19 @@ function price_format(post, num, dec, label, color) {
        if(isNaN(num))
                num = "0";
        sign = (num == (num = Math.abs(num)));
+       var max = dec=='max';
+       if(max) dec = 15 - Math.floor(Math.log(Math.abs(num)));
        if(dec<0) dec = 2;
        decsize = Math.pow(10, dec);
        num = Math.floor(num*decsize+0.50000000001);
        cents = num%decsize;
        num = Math.floor(num/decsize).toString();
-       for( i=cents.toString().length; i<dec; i++){
-               cents = "0" + cents;
-       }
+       if (max) // strip trailing 0
+               cents = cents.toString().replace(/0+$/,'');
+       else
+               for( i=cents.toString().length; i<dec; i++){
+                       cents = cents + "0";
+               }
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
                num = num.substring(0,num.length-(4*i+3))+user.ts+
                        num.substring(num.length-(4*i+3));