Index: ext/standard/basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.792
diff -u -r1.792 basic_functions.c
--- ext/standard/basic_functions.c	17 Jul 2006 20:52:12 -0000	1.792
+++ ext/standard/basic_functions.c	19 Jul 2006 09:44:10 -0000
@@ -2030,8 +2030,8 @@
 ZEND_BEGIN_ARG_INFO_EX(arginfo_number_format, 0, 0, 1)
 	ZEND_ARG_INFO(0, number)
 	ZEND_ARG_INFO(0, num_decimal_places)
-	ZEND_ARG_INFO(0, dec_seperator)
-	ZEND_ARG_INFO(0, thousands_seperator)
+	ZEND_ARG_INFO(0, dec_separator)
+	ZEND_ARG_INFO(0, thousands_separator)
 ZEND_END_ARG_INFO()
 
 static
Index: ext/standard/math.c
===================================================================
RCS file: /repository/php-src/ext/standard/math.c,v
retrieving revision 1.135
diff -u -r1.135 math.c
--- ext/standard/math.c	16 Jul 2006 10:49:06 -0000	1.135
+++ ext/standard/math.c	19 Jul 2006 09:42:01 -0000
@@ -42,16 +42,24 @@
 #endif
 
 #define PHP_ROUND_WITH_FUZZ(val, places) {			\
-	double tmp_val=val, f = pow(10.0, (double) places);	\
-	tmp_val *= f;					\
-	if (tmp_val >= 0.0) {				\
-		tmp_val = floor(tmp_val + PHP_ROUND_FUZZ);	\
-	} else {					\
-		tmp_val = ceil(tmp_val - PHP_ROUND_FUZZ);	\
-	}						\
-	tmp_val /= f;					\
-	val = !zend_isnan(tmp_val) ? tmp_val : val;	\
-}							\
+	if (places) { \
+		double tmp_val=val, f = pow(10.0, (double) places);	\
+		tmp_val *= f;					\
+		if (tmp_val >= 0.0) {				\
+			tmp_val = floor(tmp_val + PHP_ROUND_FUZZ);	\
+		} else {					\
+			tmp_val = ceil(tmp_val - PHP_ROUND_FUZZ);	\
+		}						\
+		tmp_val /= f;					\
+		val = !zend_isnan(tmp_val) ? tmp_val : val;	\
+	} else { \
+		if (val >= 0.0) {				\
+			val = floor(val + PHP_ROUND_FUZZ);	\
+		} else {					\
+			val = ceil(val - PHP_ROUND_FUZZ);	\
+		}						\
+	} \
+}								\
 
 /* {{{ proto int abs(int number)
    Return the absolute value of the number */
@@ -970,14 +978,18 @@
 	int integral;
 	int tmplen, reslen=0;
 	int count=0;
-	int is_negative=0;
+	int is_negative=0, trim_dec=0;
 
 	if (d < 0) {
 		is_negative = 1;
 		d = -d;
 	}
 
-	dec = MAX(0, dec);
+	if (dec < 0) {
+		trim_dec = 1;
+		dec = -dec;
+	}
+
 	PHP_ROUND_WITH_FUZZ(d, dec);
 
 	tmplen = spprintf(&tmpbuf, 0, "%.*f", dec, d);
@@ -989,6 +1001,31 @@
 	/* find decimal point, if expected */
 	dp = dec ? strchr(tmpbuf, '.') : NULL;
 
+	if (trim_dec) {
+		if (dp) {
+			s = tmpbuf + tmplen - 1;
+
+			while (*s == '0') {
+				*s-- = '\0';
+				tmplen--;
+			}
+
+			/* reset to the actual number of places left */
+			dec = s - dp;
+
+			if (*s == '.') {
+				*s-- = '\0';
+				tmplen--;
+				dp = NULL;
+			}
+
+			s = NULL;
+		} else {
+			/* if no decimal point was found, we don't want it and zeros added later */
+			dec = 0;
+		}
+	}
+
 	/* calculate the length of the return buffer */
 	if (dp) {
 		integral = dp - tmpbuf;
@@ -1068,7 +1105,7 @@
 }
 /* }}} */
 
-/* {{{ proto string number_format(float number [, int num_decimal_places [, string dec_seperator, string thousands_seperator]])
+/* {{{ proto string number_format(float number [, int num_decimal_places [, string dec_separator, string thousands_separator]])
    Formats a number with grouped thousands */
 PHP_FUNCTION(number_format)
 {
@@ -1083,23 +1120,31 @@
 		}
 		convert_to_double_ex(num);
 		tmp = _php_math_number_format(Z_DVAL_PP(num), 0, dec_point, thousand_sep);
-		RETVAL_RT_STRING(tmp, 0);
-		if (UG(unicode)) {
-			efree(tmp);
-		}
-		return;
+		break;
 	case 2:
 		if (zend_get_parameters_ex(2, &num, &dec)==FAILURE) {
 			RETURN_FALSE;
 		}
 		convert_to_double_ex(num);
+
+		if (Z_TYPE_PP(dec) == IS_STRING || Z_TYPE_PP(dec) == IS_UNICODE) {
+			convert_to_string_ex(dec);
+
+			/* Allow thousand_sep as the second parameter (no need for the dec params with whole numbers)
+			 * if it's non-numeric -- why use a numeric seperator? Have to use 4th param for that :-)
+			 * Old behavior only changes if an empty/non-numeric-prefix string was used for dec places */
+			if (Z_STRVAL_PP(dec)[0] < '0' || Z_STRVAL_PP(dec)[0] > '9') {
+				/* Will be 0 ('\0') with empty string */
+				thousand_sep = Z_STRVAL_PP(dec)[0];
+
+				tmp = _php_math_number_format(Z_DVAL_PP(num), 0, dec_point, thousand_sep);
+				break;
+			}
+		}
+
 		convert_to_long_ex(dec);
 		tmp = _php_math_number_format(Z_DVAL_PP(num), Z_LVAL_PP(dec), dec_point, thousand_sep);
-		RETVAL_RT_STRING(tmp, 0);
-		if (UG(unicode)) {
-			efree(tmp);
-		}
-		return;
+		break;
 	case 4:
 		if (zend_get_parameters_ex(4, &num, &dec, &d_p, &t_s)==FAILURE) {
 			RETURN_FALSE;
@@ -1109,29 +1154,26 @@
 
 		if (Z_TYPE_PP(d_p) != IS_NULL) { 
 			convert_to_string_ex(d_p);
-			if (Z_STRLEN_PP(d_p)>=1) {
-				dec_point=Z_STRVAL_PP(d_p)[0];
-			} else if (Z_STRLEN_PP(d_p)==0) {
-				dec_point=0;
-			}
+
+			/* Will be 0 ('\0') with empty string */
+			dec_point = Z_STRVAL_PP(d_p)[0];
 		}
 		if (Z_TYPE_PP(t_s) != IS_NULL) {
 			convert_to_string_ex(t_s);
-			if (Z_STRLEN_PP(t_s)>=1) {
-				thousand_sep=Z_STRVAL_PP(t_s)[0];
-			} else if(Z_STRLEN_PP(t_s)==0) {
-				thousand_sep=0;	
-			}
+
+			/* Will be 0 ('\0') with empty string */
+			thousand_sep = Z_STRVAL_PP(t_s)[0];
 		}
 		tmp = _php_math_number_format(Z_DVAL_PP(num), Z_LVAL_PP(dec), dec_point, thousand_sep);
-		RETVAL_RT_STRING(tmp, 0);
-		if (UG(unicode)) {
-			efree(tmp);
-		}
-		return;
+		break;
 	default:
 		WRONG_PARAM_COUNT;
-		break;
+		return;
+	}
+
+	RETVAL_RT_STRING(tmp, 0);
+	if (UG(unicode)) {
+		efree(tmp);
 	}
 }
 /* }}} */
