With Decimal.Round, I can only choose between ToEven and AwayFromZero, now I'd like to round it always to the smaller number, that is, like truncating, remove the digits that is out of the required decimals:
public static void Main()
{
Console.WriteLine("{0,-10} {1,-10} {2,-10}", "Value", "ToEven", "AwayFromZero");
for (decimal value = 12.123451m; value <= 12.123459m; value += 0.000001m)
Console.WriteLine("{0} -- {1} -- {2}", value, Math.Round(value, 5, MidpointRounding.ToEven),
Math.Round(value, 5, MidpointRounding.AwayFromZero));
}
// output
12.123451 -- 12.12345 -- 12.12345
12.123452 -- 12.12345 -- 12.12345
12.123453 -- 12.12345 -- 12.12345
12.123454 -- 12.12345 -- 12.12345
12.123455 -- 12.12346 -- 12.12346
12.123456 -- 12.12346 -- 12.12346
12.123457 -- 12.12346 -- 12.12346
12.123458 -- 12.12346 -- 12.12346
12.123459 -- 12.12346 -- 12.12346
I just want all those to be rounded to 12.12345, that is keep 5 decimals, and truncating remaining ones. Is there a better way to do this?