Is it necessary to specify f while initiating a float type variable.
float a =3455.67f;
If I declare and initiate it as
float a = 3455.67;
Then what will happen?
The documentation on float says:
By default, a real numeric literal on the right side of the assignment operator is treated as
double. Therefore, to initialize afloatvariable, use the suffixforF.
This means that if you do float a = 3455.67; then the compiler will refuse to implicitly convert the double to a float.
By default, a real numeric literal on the right side of the assignment operator is treated as double. Therefore, to initialize a float variable, use the suffix f or F, as in the following example:
float x = 3.5F;
If you do not use the suffix in the previous declaration, you will get a compilation error because you are trying to store a double value into a float variable.
for more details look at msdn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With