var_dump(json_decode('{"price":5.00}', true));
Result: array(1) { ["price"]=> float(5)//But the expectation is 5.00, the decimal point can be retained}
It’s not a problem with json_decode, it’s the output function itself,
var_dump(5.00);//输出float(5) echo 5.00;//输出5 print 5.00;//输出5
json_encode retains decimal points by setting optional options
echo json_encode([5.00], JSON_PRESERVE_ZERO_FRACTION);//输出[5.0],但这也不是期望的[5.00] echo sprintf('%.2f', 5);//保留两位小数
var_dump(json_decode('{"price":"5.00"}', true));
var_dump is a typed print.
https://www.bytelang.com/o/s/...
This is simple, just change 5.00 into string type
This has nothing to do with jeon_encode. It should be formatted during output.
echo number_format($price, 2, '.', '');
or
echo sprintf('%.2f', $price);
It’s not a problem with json_decode, it’s the output function itself,
json_encode retains decimal points by setting optional options
var_dump is a typed print.
https://www.bytelang.com/o/s/...
This is simple, just change 5.00 into string type
This has nothing to do with jeon_encode. It should be formatted during output.
or
var_dump(json_decode('{"price":"5.00"}', true));