I can store a number as a Long and Double in HBase. Both of them takes 8 bytes in Java.
Advantage of Using Double is that it gives a more wider range for storing Whole Numbers.
However, i think range of Long is also enough for my use.
Does anyone has any idea about the serialization and de-serialization performance of Long vs Dobule? I am interested in comparison between them.
Thanks.
If you are storing integers, use
Long. Your statement that “Advantage of Using Double is that it gives a more wider range for storing Whole Numbers” is incorrect. Both are 64 bits long, butdoublehas to use some bits for the exponent, leaving fewer bits to represent the magnitude. You can store larger numbers in adoublebut you will lose precision.In other words, for numbers larger than some upper bound you can no longer store adjacent “whole numbers”… given an integer value above this threshold, the “next” possible
doublewill be more than 1 greater than the previous number.For example
This outputs:
Note that
Another way of saying this is that
longhas just under 19 digits precision, whiledoublehas only 16 digits precision. Double can store numbers larger than 16 digits, but at the cost of truncation/rounding in the low-order digits.If you need more than 19 digits precision you must resort to
BigInteger, with the expected decrease in performance.