edink           Thu Jan 16 08:21:55 2003 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4/ext/standard  math.c 
  Log:
  MFH: recent fixes to number_format()
  
Index: php4/ext/standard/math.c
diff -u php4/ext/standard/math.c:1.97.2.3 php4/ext/standard/math.c:1.97.2.4
--- php4/ext/standard/math.c:1.97.2.3   Thu Jan  9 11:54:15 2003
+++ php4/ext/standard/math.c    Thu Jan 16 08:21:54 2003
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: math.c,v 1.97.2.3 2003/01/09 16:54:15 iliaa Exp $ */
+/* $Id: math.c,v 1.97.2.4 2003/01/16 13:21:54 edink Exp $ */
 
 #include "php.h"
 #include "php_math.h"
@@ -1011,10 +1011,14 @@
 
        /* allow for thousand separators */
        if (thousand_sep) {
-               integral += integral / 3;
+               integral += (integral-1) / 3;
        }
        
-       reslen = integral + 1 + dec;
+       reslen = integral;
+       
+       if (dec) {
+               reslen += 1 + dec;
+       }
 
        /* add a byte for minus sign */
        if (is_negative) {
@@ -1034,21 +1038,24 @@
                int topad = declen > 0 ? dec - declen : 0;
 
                /* pad with '0's */
+
                while (topad--) {
                        *t-- = '0';
                }
-                       
-               /* now copy the chars after the point */
-               memcpy(t - declen + 1, dp + 1, declen);
                
-               t -= declen;
-               s -= declen;
+               if (dp) {
+                       /* now copy the chars after the point */
+                       memcpy(t - declen + 1, dp + 1, declen);
+
+                       t -= declen;
+                       s -= declen;
+               }
 
                /* add decimal point */
                *t-- = dec_point;
                s--;
        }
-       
+
        /* copy the numbers before the decimal place, adding thousand
         * separator every three digits */
        while(s >= tmpbuf) {
@@ -1064,7 +1071,7 @@
        }
 
        efree(tmpbuf);
-
+       
        return resbuf;
 }
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to