FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » json_decode
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
json_decode [message #175082] Thu, 11 August 2011 09:23 Go to next message
Falk Fiedler is currently offline  Falk Fiedler
Messages: 3
Registered: August 2011
Karma: 0
Junior Member
hi,

i get from a API a JSON-String with the field:

"id":1070107173001

with json_decode i get:

id = 1.070107173E+12

and i can't work with this value ... is this right, what can i do?

thank you


falk
Re: json_decode [message #175084 is a reply to message #175082] Thu, 11 August 2011 10:48 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 8/11/2011 5:23 AM, Falk Fiedler wrote:
> hi,
>
> i get from a API a JSON-String with the field:
>
> "id":1070107173001
>
> with json_decode i get:
>
> id = 1.070107173E+12
>
> and i can't work with this value ... is this right, what can i do?
>
> thank you
>
>
> falk

Yes, it is correct. The value is larger than a 32 bit integer can hold,
so PHP creates a float type out of it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: json_decode [message #175085 is a reply to message #175082] Thu, 11 August 2011 13:00 Go to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 11/08/2011 11:23, Falk Fiedler escribió/wrote:
> i get from a API a JSON-String with the field:
>
> "id":1070107173001
>
> with json_decode i get:
>
> id = 1.070107173E+12
>
> and i can't work with this value ... is this right, what can i do?
>
> thank you


In my computer, it creates a float but it doesn't lose precision. You
should be able to work with it without any problem.

If you are getting scientific notation it's because you are casting it
to string with a function that does not let you choose the format. Just
handle it as number.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Using the browser's Webcache
Next Topic: to fill a select with json javascript from arrays
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 29 20:54:03 GMT 2024

Total time taken to generate the page: 0.02155 seconds