// 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 string SpecialFormat(int v, int sf) { int k = (int)Math.Pow(10, (int)(Math.Log10(v) + 1 - sf)); int v2 = ((v + k/2) / k) * k; return v2.ToString("0,0"); } public static void Main(string[] args) { int v = 2354856; Console.WriteLine(SpecialFormat(v, 1)); Console.WriteLine(SpecialFormat(v, 2)); Console.WriteLine(SpecialFormat(v, 3)); } } }