用C#写 四舍五入函数(函数版)
适用范围:长整型long(-9223272036854775808 ~ +9223272036854775808)
本代码在:Windows 2003 && Microsoft Visual Studio .NET 2003 通过
//BY: bit.Aipeli 2005-11-07 23:27:23
private double Round(double v,int x)
{
int i;
long IValue=1;
double DValue=1;
for (i=1;i<=x;i++)
{
IValue=IValue*10;
DValue=DValue/10;
}
long Int=(long)Decimal.Round(Convert.ToDecimal(v*IValue),0);
double Key=(double)(v/DValue)-Int;
double Dou=(double)Int/IValue;
if (Key>=0.5)
{
Dou+=DValue;
}
return Dou;
}
private double Round(double v,int x)
{
int i;
long IValue=1;
double DValue=1;
for (i=1;i<=x;i++)
{
IValue=IValue*10;
DValue=DValue/10;
}
long Int=(long)Decimal.Round(Convert.ToDecimal(v*IValue),0);
double Key=(double)(v/DValue)-Int;
double Dou=(double)Int/IValue;
if (Key>=0.5)
{
Dou+=DValue;
}
return Dou;
}
本代码在:Windows 2003 && Microsoft Visual Studio .NET 2003 通过