The Firebase Java API specifies that Long is a valid type to pass to setValue(). JavaScript only supports a single number type, the equivalent of Java's "double". So if I insert a number from JavaScript and retrieve it later from Java, am I going to get a Long or a Double? Is it a bad idea to use Longs in any cross-platform Firebase code, seeing as how a JavaScript client has no way of creating this type?
Asked
Active
Viewed 1,680 times
1 Answers
3
Numbers are slotted into either Longs or Doubles on the server. If the number maps exactly to a Long (i.e. is within the range of Longs, and does not have a decimal point), it will be stored as a Long. Otherwise, it will be stored as a Double.
Javascript does have less precision than Java when it comes to Longs, but if you remain within Javascript's limits, you shouldn't have a problem using Longs cross-platform.

Greg Soltis
- 1,434
- 9
- 10
-
So, just to be explicit about the answer here, if I insert a number from JavaScript with no decimal point, it will show up as a Long in Java, right? – Derek Thurn Sep 26 '13 at 20:37
-
Correct. Be aware that Javascript begins to lose precision at 2^53, so if you are dealing with larger numbers, you may want to reconsider using javascript, or consider using an alternate representation. See http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t for more details on Javascript's Numbers. – Greg Soltis Sep 27 '13 at 00:28