June 2018
Beginner
722 pages
18h 47m
English
In the Java Specification, the floating-point types (float and double) are defined as:
It means that the float type occupies 32 bits and the double type takes 64 bits. They represent positive and negative numerical values with a fractional part after the dot ".": 1.2, 345.56, 10., -1.34. By default, in Java, a numeric value with a dot in it is assumed to be of the double type. So, the following assignment causes a compilation error:
float r = 23.4;
To avoid the error, one has to indicate that the value has to be treated as a float type by appending the f or F character at the value, as follows:
float r = 23.4f;orfloat r = 23.4F;
The values ...
Read now
Unlock full access