// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class Program { public static double Floor(double x, int n) { return Math.Round(x - 0.5 * Math.Pow(10, - n), n, MidpointRounding.AwayFromZero); } public static void Test(double x) { Console.WriteLine("{0:F4} -> {1:F4} {2:F4} {3:F4}", x, Floor(x, 0), Floor(x, 1), Floor(x, 2)); } public static void Main(string[] args) { Test(1.23456); Test(1.25456); Test(0.93456); Test(1.23556); Test(1.29456); Test(1); Test(1.2); Test(1.23); Test(1.234); } } }