I need to define a variable with 2 decimals to make a simple division.
Ej
float x;
x=1/2
When I execute X has the following value: 0.0000000
I need X has 0.5
What is my error?
Thanks.
PD: I just start to program C++ using Visual Studio 2010 c++
Printable View
I need to define a variable with 2 decimals to make a simple division.
Ej
float x;
x=1/2
When I execute X has the following value: 0.0000000
I need X has 0.5
What is my error?
Thanks.
PD: I just start to program C++ using Visual Studio 2010 c++
How about this:
:wave:Code:x = 1.0/2.0;
For further information, the reason why you got the result 0 is that you where dividing two integers.
When performing arithmetics on integers, the result is always an integer. Since 0.5 is not a valid integer, it is truncated. The result is 0. At this point, the result is implicitly converted to a floating point number; 0.00000000.