// 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 Precision { public class Program { private const int REP = 1000000000; private const float DF = 0.01f; private const double DD = 0.01; private const decimal DM = 0.01m; public static void Main(string[] args) { int n; n = 0; float xf = 0; for(int i = 0; i < REP; i++) { n++; xf += DF; } Console.WriteLine("C# float says {0} x {1:F2} = {2:F2}", n, DF, xf); n = 0; double xd = 0; for(int i = 0; i < REP; i++) { n++; xd += DD; } Console.WriteLine("C# double says {0} x {1:F2} = {2:F2}", n, DD, xd); n = 0; decimal xm = 0; for(int i = 0; i < REP; i++) { n++; xm += DM; } Console.WriteLine("C# decimal says {0} x {1:F2} = {2:F2}", n, DM, xm); } } }