// 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 void Test(decimal x) { decimal y = x % 1m; int z = (int)(1000*y); decimal tmp = y; while (tmp != (int)tmp && tmp < int.MaxValue/10) { tmp *= 10; } int w = (int)tmp; Console.WriteLine(x + " " + y + " " + z + " " + w); } public static void Test(double x) { double y = x % 1; int z = (int)(1000*y); Console.WriteLine(x + " " + y + " " + z); } public static void Main(string[] args) { Test(123.456m); Test(1m/3); Test(123.456); Test(1.0/3); } } }