Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
Representation of small float numbers in json_encode

I'm executing the following code in a PHP script:

$obj = new \stdClass();
$obj->lat = 0.000011399388312455;
echo json_encode($obj) . "\n";

The output of the script is

{"lat":1.1399388312454999446e-5}

As you can see, the number is represented in exponential notation. Is there some way to represent that particular number in extended notation, in the JSON-serialized object?

The desired output is

{"lat":0.000011399388312455}

The version of PHP is 5.6.30.

P.S.: This JSON-serialized object will be sent to an external web service that doesn't accept numbers in exponential form. Moreover, it needs to be a number and not a string ({"lat":"0.000011399388312455"} won't work).

The number should not be rounded (it's a geographical coordinate).

Here are other similar questions, but they don't fit my case unfortunately.

php- floating point number shown in exponential form

Remove the "E" in a number format for very small numbers

Thank you in advance.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It is implemented in PHP 7.1 https://wiki.php.net/rfc/precise_float_value As a work around, use other JSON serializers not a default json_encode.

E notation is valid form of float representation. In php >7.1 with precision set to -1 results of your code would look like: {"lat":1.1399388312455e-5} which is absolutely the same as 0.000011399388312455 because you have 4 leading zeros.

If you still want to have leading zeroes in json i would go towards strings. They are perfectly fine for coordinates representations.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!