json_decode reformatting decimals in JSON based on locale json_decode reformatting decimals in JSON based on locale wordpress wordpress

json_decode reformatting decimals in JSON based on locale


It looks like the issue is with how PHP handles numeric values. json_decode is simply transforming 13.3 to a float, which on output or being converted to a string is the localized "13,3". However, PHP does not deal well with localized number formats.

As per this thread, using setlocale has resolved the issue (for the most part)

setlocale(LC_NUMERIC, 'C');