Php exponentially

When I output some of my double variables, they are written exponentially using fwrite. Can I set some default values ​​in PHP, where whenever a variable is displayed (copied or saved), it always happens in decimal format?

To be precise, the problem occurs when I use the json_decode method on a json string that contains a double value (which is not in exponential form). This double value after the transformation of the object becomes exponential.

+3
source share
2 answers

, ( ), :

echo rtrim(sprintf("%0.15f", $x), "0.");

, . sprintf 15 , 0 .. (, , , .)

, 15 rtrim.

+1

, json_decode / .

, PHP-float, ...

  • precision php.ini precision = 20
  • ini_set('precision', 20); PHP
  • php_value precision 20 .htaccess

, , BIGINT PHP 5.3+, json_decode : json_decode($json, true, 512, JSON_BIGINT_AS_STRING)

+3

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


All Articles