Link to home
Start Free TrialLog in
Avatar of itcaptain
itcaptainFlag for Canada

asked on

C# Rounding Whole Numbers

I have a question regarding c# and rounding.  Given the following equations c# seems to round them differently based on if a decimal is dictated in the whole number.  Is there any way to tell C# to output 7.5 regardless of the format of the code?

I am in the process of converting some legacy code and I don’t have the option of ensuring the static values are formatted with “.00”.

double test = 3000.00 / 400.00;
test = 7.5;

double test2 = 3000 / 400;
test2 = 7;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
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
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