Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

Decimals not rounding properly

I have a decimal field that holds a percentage value, such as 37.5 or 62.5

I convert that to an integer to remove the decimals. However, it isn't rounding up and down properly when it is .5

37.5 rounds up to 38.
62.5 rounds down to 62.
87.5 rounds up to 88.

Everything else works as expected.

Anyone know why this is and how to fix it?

thanks!
SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
edited my first comment.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Starr Duskk

ASKER

I should give it_saige some points since he was likely formulating his tests and response when I found the solution to be to use MidpointRounding.AwayFromZero.
Complete answer and explanation why it doesn't work.