T
T
Tereverda2021-11-28 09:43:43
PHP
Tereverda, 2021-11-28 09:43:43

PHP json returning strings not numbers?

$context = stream_context_create($options);
        $response = file_get_contents($url, false, $context);
        $response = json_decode($response, true);


The response comes from the API - from different
Numbers are floating point, but my script receives them as integers.
Should be 87.80
Comes 8780 - without a dot separating a penny.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2021-11-28
@Tereverda

const json = { float: 439000.0 }
JSON.stringify(json); // '{"float":439000}'

Need to explain?
UPD: I googled for you))
<?php

$test = [
    "price" => 4390.00
];

echo json_encode($test, JSON_PRESERVE_ZERO_FRACTION);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question