Exercise 2: Banker's Rounding — Possible Solution ==================================================================== WHY [int]2.5 IS 2 AND [int]3.5 IS 4 ------------------------------ Casting a double to [int] in PowerShell uses banker's rounding (round-half-to-even), not the "always round .5 up" rule most people assume. Under banker's rounding, a value exactly halfway between two integers rounds to whichever of those two integers is EVEN, not simply upward. 2.5 sits between 2 and 3; 2 is the even neighbor, so it rounds to 2. 3.5 sits between 3 and 4; 4 is the even neighbor, so it rounds to 4. Both results are correct under the rule this chapter describes - it isn't inconsistent, it's just a different rule than the "always round up" assumption most people carry in by default. WHAT TO USE FOR TRADITIONAL ROUND-HALF-UP BEHAVIOR ------------------------------ Per this chapter, [math]::Round($value, 0, [MidpointRounding]::AwayFromZero) should be used instead of a bare [int] cast whenever traditional "always round .5 up" behavior is actually wanted. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly names banker's rounding (round-half-to-even) as the mechanism, correctly explains why 2.5 rounds down to 2 while 3.5 rounds up to 4 (both landing on the nearest even number), and correctly names [math]::Round with MidpointRounding.AwayFromZero as the alternative for traditional rounding.