0

Why is the following a wrong declaration:

float realNumber = 12.5;

Why do I need to put f at the end like this:

float realNumber = 12.5f;

What is the purpose of declaring it a float datatype if the default is double? Sorry, but I am just starting to learn C# through this website and I am a beginner. Thanks!

Brian
  • 2,078
  • 1
  • 15
  • 28
  • I understand what they were saying in the other answer. But unless the answer to my question is "because that is how C# was designed" it doesn't answer what the purpose of the float data type is if you still have to put an `f` at the end. – Brian May 23 '18 at 11:54
  • `12.5` literal is of type `double`. There is no implicit conversion from `double` to `float` (because that conversion is not loseless). For that reason you cannot assign value of type `double` to variable of type `float`. – Evk May 23 '18 at 11:56
  • 1
    Because that's how C# was designed. They had to pick _a_ default data type for floating-point values. – CodeCaster May 23 '18 at 11:57
  • 1
    @CodeCaster The way you said it made it click for me now. They have two data types for the same kind of real number (only one has more decimals). Evk's implicit conversion comment makes sense now, too. Thanks! – Brian May 23 '18 at 12:05

0 Answers0