Json_decode reformat decimal to language based JSON

I am currently working on a website localized in several languages, and I am having a problem when json_decode reformats decimal numbers in JSON strings depending on the language. When the locale is set to "en", the decimal places remain intact. However, in the fr_FR locale they are replaced, for example, with 13.3.

JSON Source:

{"debug":[{"id":13.3}]}

Exit for "en"

Array
(
    [debug] => Array
        (
            [0] => Array
                (
                    [id] => 13.3
                )
        )
    )

Output for "fr_FR"

Array
(
    [debug] => Array
        (
            [0] => Array
                (
                    [id] => 13,3
                )
        )
    )

Is there a reason json_decode does this? Is there any way to prevent this?

The error causes problems with the Gravity Forms Wordpress plugin, but I have already highlighted the problem for the json_decode function.

+4
1

, , PHP . json_decode 13.3 float, "13,3". PHP .

thread setlocale ( )

setlocale(LC_NUMERIC, 'C');
+4

Source: https://habr.com/ru/post/1528778/


All Articles