VB.NET
'''
<summary>
''' 特定の小数点以下の精度で四捨五入を行う方法
'''
</summary>
'''
<param name="dblValue"></param>
'''
<param name="intDgt"></param>
'''
<returns></returns>
Public Shared Function
RoundWitnDgt(dblValue As Double, intDgt As Integer) As Double
Dim
dblCF As Double = System.Math.Pow(10, intDgt)
Return If(dblValue
> 0, System.Math.Floor((dblValue * dblCF) + 0.5) / dblCF, System.Math.Ceiling((dblValue
* dblCF) - 0.5) / dblCF)
End Function
C#
///
<summary>
/// 特定の小数点以下の精度で四捨五入を行う方法
///
</summary>
///
<param name="dblValue"></param>
///
<param name="intDgt"></param>
///
<returns></returns>
public static double
RoundWitnDgt(double dblValue, int intDgt)
{
double
dblCF = System.Math.Pow(10, intDgt);
return
dblValue > 0 ? System.Math.Floor((dblValue * dblCF) + 0.5) /
dblCF :
System.Math.Ceiling((dblValue
* dblCF) - 0.5) / dblCF;
}