Link to home
Start Free TrialLog in
Avatar of _agx_
_agx_Flag for United States of America

asked on

What happens to fractional values when casting from double to int? (beginner)

From what I can tell, the fractional values are truncated and the result is  Math.floor().

        double dx = 4968525.66;
        Console.WriteLine((int)dx); // 4968525
        Console.WriteLine(Math.Floor(dx)); // 4968525

Is that always true? Any difference for negative values?  
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
Avatar of _agx_

ASKER

>> for negative values floor returns the value going away from zero, not towards.

Ah, right. I'm forgetting basic math ... ;-)

Avatar of _agx_

ASKER

Just the answer I was looking for, thanks.
NP. Glad to help  = )