Java初体验之float type

本文详细对比了Java和C/C++中float和double类型的使用、大小、精度以及存储方式。

Both C and Java define floating-point types named float and double, which
represent single- and double-precision floating-point values, respectively. Java
floating-point types are, however, represented in a completely different format from
their C/C++ counterparts. As in C, Java floating-point values can be represented
with an exponential portion.

The float type in C is used to store a signed floating-point number value. The
exact size of the float type is specified by the compiler, but in general the int type
is 32 bits (including a sign bit), yielding a range of approximately -34.4E-38 through
3.4E+38. The float type can generally be used safely to store values of six to
seven digits of precision.

The Java float is also used to store signed floating-point number values, but the
language specifies that 32 bits (including a sign bit) are always used to store IEEE
754 floating-point values. Floating-point literals are assumed to be of type double,
so if you specify a float literal you need to append the letter f or F.
The double type in C is used to store a signed floating-point number value. The
exact size of the double type is specified by the compiler, but in general the
double type is 64 bits (including a sign bit), yielding a range of approximately
-1.7E-308 through 1.7E-308. The double type can generally be used safely to store
values of 14 to 15 digits of precision.
The Java double is also used to store signed floating-point number values, but the
language specifies that 64 bits (including a sign bit) are always used to store IEEE
754 floating-point values. Floating-point literals are always assumed to be of type
double, but you can append the letter d or D if you wish.

转载于:https://www.cnblogs.com/allenblogs/archive/2011/11/07/2239226.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值