double num;
zend_long dec = 0;
char *thousand_sep = NULL, *dec_point = NULL;
- char thousand_sep_chr = ',', dec_point_chr = '.';
size_t thousand_sep_len = 0, dec_point_len = 0;
ZEND_PARSE_PARAMETERS_START(1, 4)
Z_PARAM_STRING_OR_NULL(thousand_sep, thousand_sep_len)
ZEND_PARSE_PARAMETERS_END();
- switch(ZEND_NUM_ARGS()) {
- case 1:
- RETURN_STR(_php_math_number_format(num, 0, dec_point_chr, thousand_sep_chr));
- break;
- case 2:
- RETURN_STR(_php_math_number_format(num, (int)dec, dec_point_chr, thousand_sep_chr));
- break;
- case 4:
- if (dec_point == NULL) {
- dec_point = &dec_point_chr;
- dec_point_len = 1;
- }
-
- if (thousand_sep == NULL) {
- thousand_sep = &thousand_sep_chr;
- thousand_sep_len = 1;
- }
-
- RETVAL_STR(_php_math_number_format_ex(num, (int)dec,
- dec_point, dec_point_len, thousand_sep, thousand_sep_len));
- break;
- default:
- WRONG_PARAM_COUNT;
+ if (dec_point == NULL) {
+ dec_point = ".";
+ dec_point_len = 1;
+ }
+ if (thousand_sep == NULL) {
+ thousand_sep = ",";
+ thousand_sep_len = 1;
}
+
+ RETURN_STR(_php_math_number_format_ex(num, (int)dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len));
}
/* }}} */
--- /dev/null
+--TEST--
+number_format should use default values when passed null
+--FILE--
+<?php
+
+$number = 2020.1415;
+
+var_dump(number_format($number, 2, null, 'T'));
+var_dump(number_format($number, 2, 'F', null));
+
+?>
+--EXPECT--
+string(8) "2T020.14"
+string(8) "2,020F14"