Java: Convert from Number to long
Use Number.longValue
:
Number n = ...
long l = n.longValue()
Note that this simply discards all but the lowest 64 bits. If the Number
is outside of the range −9,223,372,036,854,775,808…9,223,372,036,854,775,807 the conversion my have unexpected results.
Number | longValue() |
---|---|
1,000 | 1,000 |
9,223,372,036,854,775,807 | −1 |
9,223,372,036,854,775,808 | 0 |
9,223,372,036,854,775,809 | 1 |
18,446,744,073,709,551,616 | 0 |
10,000,000,000,000,000,000 | −1,981,284,352 |
−10,000,000,000,000,000,000 | 1,981,284,352 |
Comments
Be the first to comment!