+ 2

Float x=3.5f why we need f as suffix?

4th Feb 2019, 12:41 PM
Jayesh@2806 [ROYAL CODER]
Jayesh@2806 [ROYAL CODER] - avatar
4 Antworten
+ 4
A float data type in Java stores a decimal value with 6-7 total digits of precision. So, for example, 12.12345 can be saved as a float, but 12.123456789 can't be saved as a float. When representing a float data type in Java, we should append the letter f to the end of the data type; otherwise it will save as double. The default value of a float in Java is 0.0f. Float data type is used when you want to save memory and when calculations don't require more than 6 or 7 digits of precision. Taken from: https://study.com/academy/lesson/java-floating-point-numbers.html
4th Feb 2019, 1:49 PM
Lambda_Driver
Lambda_Driver - avatar
+ 4
Correct uses: float fl=4.2f; float fl= 4.2F; mistake: float fl=4.2;
4th Feb 2019, 1:43 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 2
Without the F suffix, the compiler will treat them as doubles.
4th Feb 2019, 1:27 PM
Seniru
Seniru - avatar
0
Upto which decimal place double can store
4th Feb 2019, 2:29 PM
Jayesh@2806 [ROYAL CODER]
Jayesh@2806 [ROYAL CODER] - avatar