Reputation:
I am generally confused when defining double and float variables and as far as I know, it is good practice to add "d", "f", etc. at the end of double, float values. However, as the IDE does not warn me, generally I omit them and think it would also be ok and no need to add these letters. Regarding to these variables:
1. Is there any letter except from "d" and "f" added to the variable definitions (double, float) in Java?
2. Why do we add these letters at the end of float and double variable definitions? And should we use or not?
3. When defining these variables (except from List, Map, etc.) as shown below, should I prefer primitive or wrapper class version of them?
I simply define a double like:
double quantityAmount = 200d;
// or
double quantityAmount = 200;
Could you please clarify me about this issue?
Upvotes: 0
Views: 1519
Reputation: 16
Upvotes: 0
Reputation: 36346
300
, it will call the int
version, if you pass 300d
, it will call the double version.Upvotes: 1