问题描述
Firebase Java API指定Long是要传递给setValue()的有效类型.JavaScript仅支持单个数字类型,等效于Java的双精度".因此,如果我从JavaScript中插入一个数字,以后再从Java中检索它,那么我将得到Long还是Double?在JavaScript客户端无法创建这种类型的情况下,在任何跨平台的Firebase代码中使用Longs是一个坏主意吗?
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?
推荐答案
数字在服务器上被放入Longs或Doubles中.如果数字正好映射到Long(即在Longs的范围内,并且没有小数点),它将被存储为Long.否则,它将被存储为Double.
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.
就Longs而言,Java的精度确实不如Java,但如果您仍在Java的范围内,那么使用Longs跨平台就不会有问题.
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.
这篇关于Firebase如何处理多头和双头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!