With Decimal.Round, I can only select ToEvenand AwayFromZero, now I would like to round it always to a smaller number, i.e. as a truncation, remove the numbers that are behind the zero commas:
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));
}
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.12345which store 5 decimal places and crop the rest. Is there a better way to do this?
source
share