Float and double datatype in Java

2019-01-02 14:59发布

The float data type is a single-precision 32-bit IEEE 754 floating point and the double data type is a double-precision 64-bit IEEE 754 floating point.

What does it mean? And when should I use float instead of double or vice-versa?

7条回答
琉璃瓶的回忆
2楼-- · 2019-01-02 15:31

A float gives you approx. 6-7 decimal digits precision while a double gives you approx. 15-16. Also the range of numbers is larger for double.

A double needs 8 bytes of storage space while a float needs just 4 bytes.

查看更多
登录 后发表回答