Floating-point result for decimal variable

1

I have the following variable:

decimal resultado = 0.0m;

I need to assign the result of a division to this variable:

resultado = (1 / 2) * (-1);

The result has been 0 , but should be -0.5 . I think I need to do some kind of conversion. Could someone help me?

    
asked by anonymous 11.08.2015 / 13:50

1 answer

1

Only put the m to represent the decimal, thus without the m, is an integer, disregarding the decimal places.

result = (1m / 2m) * (-1m);

    
11.08.2015 / 14:01