四捨五入

C#色温度関係のプログラムを作成中。

その際指定した小数第○○位で四捨五入する機能が欲しくなった。

public static double ToHalfAdjust(double dValue, int iDigits)
{
double dCoef = System.Math.Pow(10, iDigits);

return dValue > 0 ? System.Math.Floor((dValue * dCoef) + 0.5) / dCoef :
System.Math.Ceiling((dValue * dCoef) - 0.5) / dCoef;
}

※参考サイト
 「C#VB.NET の入門サイト」
 http://jeanne.wankuma.com/tips/csharp/math/halfadjust.html
 いつも御世話になっております。