json - PHP have decimal numbers with json_encode -
i have issue json code decimal numbers must encoded without quotes , maintain 2 decimal places
e.g.
{12.34, 33.40, 25.00}
my problem array have creates numbers string
foreach($numbers $n) { $result[] = number_format($n, 2, '.', ''); } json_encode($result); // result = {"12.34", "33.40", "25.00"}
you can utilize floatval()
:
$result[] = floatval(number_format($n, 2, '.', ''));
php json
No comments:
Post a Comment