PHP中的数字格式5.5到5.50
字段值为:5.5 但我想表现得像:5.50 我试过了PHP中的数字格式5.5到5.50,php,date,number-formatting,Php,Date,Number Formatting,字段值为:5.5 但我想表现得像:5.50 我试过了 number_format($_REQUEST['price'], 2, '.', ''); round($_REQUEST['price'],2); 但所有显示的都是5.5,这是因为您在格式化数字后正在对其进行四舍五入 您需要先将其四舍五入(或在格式化过程中)。这应该起作用: number_format(round($_REQUEST['price'], 2), 2, '.', ''); 您需要将number_format()的结果存储
number_format($_REQUEST['price'], 2, '.', '');
round($_REQUEST['price'],2);
但所有显示的都是5.5,这是因为您在格式化数字后正在对其进行四舍五入 您需要先将其四舍五入(或在格式化过程中)。这应该起作用:
number_format(round($_REQUEST['price'], 2), 2, '.', '');
您需要将number_format()的结果存储在一个变量中,否则调用它就没有意义了