// 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; class MainClass { public static void Main(string[] args) { int n1 = 20; int n2 = 30; double x = (100.0 * n1) / n2; double x1a = ((int)(10 * x)) / 10.0; double x1b = ((int)(10 * (x + 0.05))) / 10.0; double x1c = Math.Round(x, 1); Console.WriteLine("Before rounding " + x); Console.WriteLine("Manual round down " + x1a); Console.WriteLine("Manual round nearest " + x1b); Console.WriteLine("Builtin round nearest " + x1c); } }