Floating point result for decimal variable

Asked

Viewed 1,662 times

1

I have the following variable:

decimal resultado = 0.0m;

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

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

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

1 answer

1


Only place m to represent decimal, this way without m, is an integer, disregarding the decimal places.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.