+ 6
Which ones are valid as floats? 2, 0, 5.5f, 4.3 And the answers are 2, 0 and 5.5f. Is question correct or I need some education?
Challenge question
3 Réponses
+ 5
Ok making sense there Tibor. Thanks
+ 4
https://csharp.net-tutorials.com/data-types/floating-points/#aelm5191
david chongo look this tutorial.
Answer is correct:
1) 0, 2 - we can use as float.
2) 4.3 - is double data type, it's not valid as float.
3) 5.5f - float. 'f' - the symbol of float.
+ 3
I tried it on the code playground. If you do this in C#:
float x = 4.3;
Console.WriteLine(x);
You get an error message because the default floating point type of C# is double, which has more precision than float. Therefore it is not possible for the compiler to implicitly downcast it. So you either use the f suffix to signal the float notation, or do an explicit cast:
float x = 4.3f;
float y = (float) 4.3;
On the other hand it is possible to upcast integers to float values, because no precision is lost.