+ 6

Is float i=2.5; correct in java?

21st Mar 2018, 9:38 AM
Vartika Pahuja
Vartika Pahuja - avatar
4 Respuestas
+ 22
there will be loss of precision while converting double to float [2.5 is treated as a double type value] //to prevent that U can write ::: ⚫float i=(float)2.5; //typecasted from double to float ⚫float i=2.5f; //its in float
21st Mar 2018, 9:51 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 13
I agree
21st Mar 2018, 10:13 AM
アルゴリズム X
アルゴリズム X - avatar
+ 5
add f to the end float i =2.5f;
21st Mar 2018, 9:44 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
add f with it, otherwise it will be threaten as a double value and will produce an error
19th Jul 2018, 5:06 AM
Abdul Wahab Khan
Abdul Wahab Khan - avatar