2

Did you know that theres no real long in php (if so, please tell me how to cast..)?

And did you know that mongodb decides what it puts into it's collection?

I have no idea how to force it to set an int64 instead of int32..

Comments
  • 0
    With PHP you need to use the 64 bit version to get 64 bit integers.

    If your host can't provide that you have to use strings (and the bc math extension if you wish to operate on the numbers).

    Since PHP retardedly converts numbers that are bigger than PHP_INT_MAX to float i would recommend that you always use bc math for large values (it prevents nasty surprises when your integers are silently cast to float and rounding errors start creeping in).
  • 0
    As for mongo, it is up to you to decide what to put in a collection, a good way to get a bit better control is to use bson for your data (then you can explicitly specify the types), or convert from json instead of from php arrays. (then you can get some control over the types by for example stripping quotes from your big numbers (which would be strings in php)
  • 1
    Thank you, didn't knew that bcmath makes any difference
  • 0
    @GamerFac3 Mongo is limited to 64 bit integers though, and 128bit floats so it might be a good idea to store big integer values as strings there as well.
  • 1
    @itsnotmyfault They aren't too big. I just got a problem that int32 cannot be used in java
Add Comment