I need to know a simple question, how is float sum = 1.1f + 1.2f;
different from float sum = (float)(1.1+ 1.2);
It is a C# code btw.
Thanks in advance
I need to know a simple question, how is float sum = 1.1f + 1.2f;
different from float sum = (float)(1.1+ 1.2);
It is a C# code btw.
Thanks in advance
The difference between the two exps is that in the first expression, the operands are explicitly cast to float using the f suffix. While the second expression, the operands are implicitly cast to double (the default type for floating-point literals in C#), and then explicitly cast to float using the (float) cast operator.
So, both expressions are equivalent and will produce the same result. However, the first expression is generally considered more readable, as it explicitly indicates that the operands are float values.
What is the problem you're trying to solve ?