public static class Program
public static void Main()
var temp = 4.56769983291626;
Console.WriteLine(string.Format("Truncate: {0}",TruncateToSignificantDigits(temp, 3)));
Console.WriteLine(string.Format("Round: {0}",TruncateToSignificantDigits(temp, 3)));
public static double ApplySignificantFigures(double value)
return TruncateToSignificantDigits(RoundToSignificantDigits(value, 3), 3);
private static double RoundToSignificantDigits(double d, int digits)
double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(d))) + 1);
return scale * Math.Round(d / scale, digits);
private static double TruncateToSignificantDigits(double d, int digits)
double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(d))) + 1 - digits);
return scale * Math.Truncate(d / scale);
private static double NewRoundToSignificantDigits(double d, int digits)
double leftSideNumbers = Math.Floor(Math.Log10(Math.Abs(d))) + 1;
double scale = Math.Pow(10, leftSideNumbers);
double result = scale * Math.Round(d / scale, digits, MidpointRounding.AwayFromZero);
if ((int)leftSideNumbers >= digits)
return Math.Round(result, 0, MidpointRounding.AwayFromZero);
return Math.Round(result, digits - (int)leftSideNumbers, MidpointRounding.AwayFromZero);