Improve rounding for all platforms.

Thanks Peter Szücz for this solution, which works best on all platforms.
This solution also removes the risk of something else altering the
rounding mode.