Rounding of float values

I’d first convert to Decimal and then use Math.Round on the result. This conversion is not strictly necessary, but I always feel a bit uneasy if I round to decimal places while using binary floating points.

Math.Round((Decimal)f, 3, MidpointRounding.AwayFromZero)

You should also look into the choice of MidpointRounding, since by default this uses Banker’s round, which is not what you are used to from school.

Leave a Comment