Division in C# to get exact value

c#, floating-point, integer-division

Solution

try:

 double result = (double)150/100;

When you are performing the division as before:

double result = 150/100;

The devision is first done as an Int and then it gets cast as a double hence you get 1.0, you need to have a double in the equation for it to divide as a double.

Problem

If I divide 150 by 100, I should get 1.5. But I am getting 1.0 when I divided like I did below: ``` double result = 150 / 100; ``` Can anyone tell me how to get 1.5?

Original source

Related problems