# Problem operating with doubles

Probably will sound a stupid question but I have:

``````double value = 0;
value = 2 - (10 / 20);
return value ; // return 2
``````

and testign with d

``````double value = 0;
value = 2 - (10 / 20d);
return value ; // return 1.5
``````

How should I work with doubles? have to add “d” next to a value with a possible decimal result??? How this exactly works? I dont want to check AAAAALLLL my code and testing each operation!

Thank you.

Yes, working with doubles is the same as working with floats, you need to be careful with how you write the numbers in your operations.

The fact is that in your first version:

``````double value = 0;
value = 2 - (10 / 20);
return value ; // return 2
``````

You have a double variable however your entire operation, ( 2 - ( 10 / 20)) is working only with integers, since you aren’t specifying a “f” for float or a “d” for double. 10 / 20 is an integer division not a float, nor a double division, and from an integer point of view, 20 cannot divide 10, there’s no way you can fit a 20 inside a 10, so you get 0 as a result. 2 - 0 = 2 so you get a 2 that is an integer and then C#, with enormous kindness and understanding, automatically casts your result int into a double so it can be stored inside your variable of type double, instead of throwing an type error.

``````double value = 0;