I'm learning Java using Introduction to Programming with Java: A Problem Solving approach. The discussion of constants has me a little confused.
The statement is made that "The default type for floating-point constants is double. Then they show the following example:
float gpa = 2.30;
float mpg;
mpg = 28.6;
They indicate that 2.30 and 28.6 default to double data type.
BUT they've told gpa to be a float. They further indicate that if you REALLY want gpa to be a float then declare it as:
float gpa = 2.30f;
But havent't I already told gpa to be a float when I use float gpa = 2.30. Why do I have to tell it "twice" by using f after my value? Obviously, I'm missing something in my understanding.
The statement is made that "The default type for floating-point constants is double. Then they show the following example:
float gpa = 2.30;
float mpg;
mpg = 28.6;
They indicate that 2.30 and 28.6 default to double data type.
BUT they've told gpa to be a float. They further indicate that if you REALLY want gpa to be a float then declare it as:
float gpa = 2.30f;
But havent't I already told gpa to be a float when I use float gpa = 2.30. Why do I have to tell it "twice" by using f after my value? Obviously, I'm missing something in my understanding.