问题,如题;例:6.66666666666 → 6.76.55555555555 → 6.66.44444444444 → 6.4

解决方案 »

  1.   

    Math.Round(6.66666666666,1) 不可以吗?
      

  2.   

    Console.WriteLine(Math.Round(6.66666666666, 1, MidpointRounding.AwayFromZero).ToString());
    Console.WriteLine(6.66666666666.ToString("f1"));
    Console.WriteLine(Math.Round(6.55555555555, 1, MidpointRounding.AwayFromZero).ToString());
    Console.WriteLine(6.55555555555.ToString("f1"));
    Console.WriteLine(Math.Round(6.44444444444, 1, MidpointRounding.AwayFromZero).ToString());
    Console.WriteLine(6.44444444444.ToString("f1"));
      

  3.   


    double d=6.66666666666 ;
    d=d*10;
    float i=(int)d;
    i=i/10;
    思路是乘以10左移小数点一位,之后利用(int)强制转换切点多余的小数部分,最后再除以10把结果赋给一个float型。
      

  4.   

      /// <summary>
            /// 四舍五入
            /// </summary>
            /// <param name="nuber">要进行四舍五的数</param>
            /// <param name="point">要保留的小数位数</param>
            /// <returns></returns>
            public static double Round(double nuber, int point)
            {
                double tem = Math.Pow(10, point);
                double ret = nuber * tem;
                double min = Math.Floor(ret);
                if (ret >= min + 0.5)
                {
                    //大于五入
                    ret = min + 1;
                }
                else
                {
                    //小于五舍
                    ret = min;
                }
                return ret / tem;
            }