java floating-point data types

About floating-point data types:
float single precision [4 bytes]
double [8-byte double precision, high accuracy]
precision double is too low, not suitable for financial software.
Financial issues related to money, requiring high precision, so the sun se library on the basis of which
to prepare for higher accuracy programmer type, but this is a type of reference data types, not part of the basic data types, it is: java.math.BigDecimal

In the java language among all floating point literals [3.0], the default type is treated as a double, to float as the literal type processing, to add F / f behind literal.
Such as:
double = 3.0;
3.0 type double literal value
d is double variable
type conversion absent

5.1 is a double type literal
f is a variable of type float
mass is converted into a small capacity type need to enhance conversion system operator, the following procedure compile error.
float f = 5.1;
Solution: a (cast)
a float F = (a float) 5.1;
solution: bis (not cast)
a float F = 5.1f;

Note:
Double and float inside the computer are approximations binary storage when stored.
In the real world there are some among the number is infinite loop, for example: 3.3333333333333333333333 ...
computer's resources are limited, with limited resources to store unlimited data storage can only approximate.

Guess you like

Origin www.cnblogs.com/zhuojinyong/p/11605610.html