diff --git a/ext/standard/math.c b/ext/standard/math.c index ad2823ea49bf6..341b84396447b 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1136,6 +1136,7 @@ PHP_FUNCTION(number_format) { double num; zend_long dec = 0; + int dec_int; char *thousand_sep = NULL, *dec_point = NULL; size_t thousand_sep_len = 0, dec_point_len = 0; @@ -1156,7 +1157,13 @@ PHP_FUNCTION(number_format) thousand_sep_len = 1; } - RETURN_STR(_php_math_number_format_ex(num, (int)dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len)); + if (dec >= 0) { + dec_int = ZEND_LONG_INT_OVFL(dec) ? INT_MAX : (int)dec; + } else { + dec_int = ZEND_LONG_INT_UDFL(dec) ? INT_MIN : (int)dec; + } + + RETURN_STR(_php_math_number_format_ex(num, dec_int, dec_point, dec_point_len, thousand_sep, thousand_sep_len)); } /* }}} */