自己做一个四舍五入的function:
int f1(float fInput)
{
    int iResult;
    iResult = fInput - (int)fInput <= 0.4 ? (int)fInput : (int)fInput + 1;
    return iResult;
}临时写的,没有测试过

解决方案 »

  1.   

    要四舍五入?很简单:
    (int)(0.5+0.5)就是1,所以,对于从十分位四舍五入到个位只要在强行转换到int之前先加0.5,其他的位类似!
      

  2.   

    double x=0.5;
    this.Label1.Text=x.ToString("f0");
      

  3.   

    这个跟数据类型的隐式转换和显式转换有关系,
    显式转换到int类型小数点右边的值将丢失
      

  4.   

    我后来有查看了相关资料,在.NET中有下面的方法可以使用:
    Math.Round可以实现四舍五入。关于揭贴,你进入管理,就什么都知道了。
      

  5.   

    triout(Daview)
    很聪明
    我至少没想到
      

  6.   

    Math.Round 方法  [C#]请参见
    Math 类 | Math 成员 | System 命名空间 
    语言
    C#C++JScriptVisual Basic全部显示
    返回最接近指定值的数字。重载列表
    返回最接近指定值的整数。[Visual Basic] Overloads Public Shared Function Round(Decimal) As Decimal
    [C#] public static decimal Round(decimal);
    [C++] public: static Decimal Round(Decimal);
    [JScript] public static function Round(Decimal) : Decimal;
    返回最接近指定值的整数。[Visual Basic] Overloads Public Shared Function Round(Double) As Double
    [C#] public static double Round(double);
    [C++] public: static double Round(double);
    [JScript] public static function Round(double) : double;
    返回具有指定精度、最接近指定值的数。[Visual Basic] Overloads Public Shared Function Round(Decimal, Integer) As Decimal
    [C#] public static decimal Round(decimal, int);
    [C++] public: static Decimal Round(Decimal, int);
    [JScript] public static function Round(Decimal, int) : Decimal;
    返回具有指定精度、最接近指定值的数。[Visual Basic] Overloads Public Shared Function Round(Double, Integer) As Double
    [C#] public static double Round(double, int);
    [C++] public: static double Round(double, int);
    [JScript] public static function Round(double, int) : double;
    示例
    [Visual Basic, C#, C++] 下面的代码演示就近舍入。[Visual Basic, C#, C++] 注意   此示例显示如何使用 Round 的一个重载版本。有关其他可用示例,请参阅单独的重载主题。
    [Visual Basic] 
    Math.Round(3.44, 1) 'Returns 3.4.
    Math.Round(3.45, 1) 'Returns 3.4.
    Math.Round(3.46, 1) 'Returns 3.5.[C#] 
    Math.Round(3.44, 1); //Returns 3.4.
    Math.Round(3.45, 1); //Returns 3.4.
    Math.Round(3.46, 1); //Returns 3.5.[C++] Math::Round(3.44, 1); //Returns 3.4.
    Math::Round(3.45, 1); //Returns 3.4.
    Math::Round(3.46, 1); //Returns 3.5.[JScript] 没有可用于 JScript 的示例。若要查看 Visual Basic、C# 或 C++ 示例,请单击页左上角的语言筛选器按钮 。
      

  7.   

    triout(Daview) 老兄看清楚那是不是四舍五入 !!
    最接近 a 的整数。如果 a 在两个整数的中间,其中之一按定义是偶数,另一个是奇数,则返回偶数。此方法的行为遵循 IEEE 标准 754 的第 4 节。这种舍入有时称为就近舍入或银行家舍入 
    Math.Round(4.4); //Returns 4.0.
    Math.Round(4.5); //Returns 4.0.  <---仔细看清楚!!!
    Math.Round(4.6); //Returns 5.0.
      

  8.   

    差点搞错。Math.Round()并不是四舍五入。triout(Daview)的方法最高。