2

I'm trying to get data from facebook. So I try to get the user_id from their arrays.
Problem is some user_id are SO LONG that when I try to get it it returns something like

1.00003247906E+14

instead of

100003247905698

How do I fix this? I need the actual user_id.

I tried using:

$targets = (string)($status->actor_id);

But its still returning the same.

4
  • By default, PHP will convert all integers that is out of range to float. Use BC Math to handle big integer (but seems it is a bit overwhelming)
    – Raptor
    Apr 2, 2013 at 7:53
  • do you need them as integers? for most cases handling them as strings should work. Apr 2, 2013 at 7:55
  • OP already tried to cast it to string
    – Raptor
    Apr 2, 2013 at 7:56
  • No idea about Facebook but you need to retrieve the ID as string in the first place. Once it's become a PHP floating point number, you can't assure you haven't lost precision. Apr 2, 2013 at 7:57

3 Answers 3

0

You can try $targets = sprintf('%0.0f',$status->actor_id)

0
0

A quick fix of this :

printf("%14.0f", 1.00003247906E+14);

will print

100003247905698
5
  • And how do you know that ...06 actually represents ...05698? Apr 2, 2013 at 7:59
  • @ÁlvaroG.Vicario according to the OP this should be the number. Apr 2, 2013 at 8:00
  • That was just an example. If the knew the ID in advance, he could just define it as string in the first place. 100003247905697, 100003247905698, 100003247905699... they all print as 1.00003247906E+14. Apr 2, 2013 at 8:03
  • Is there any other way? Like getting the data as string? It still wont work. :(
    – madziikoy
    Apr 2, 2013 at 8:11
  • instead of using printf() to print it out, you can use sprintf() to get the string back
    – Raptor
    Apr 2, 2013 at 8:12
0

$targets = (string)($status->actor_id); must be returning and invalid value, because the invalid value must already be inside $status

Are you actually printing the retrieved user_id directly (like via print_r($status))?

1
  • ah k. i guess assuming code not posted in this question is probably not a good idea
    – mn.
    Apr 2, 2013 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.