我想把取出来的float数据类型只保留小数点后两位,该如何做呢

解决方案 »

  1.   

    float x = 3.22232f;
    x = System.Math.Round(x, 2);
      

  2.   

    float x = 3.22232f;
    x = (float)System.Math.Round(x, 2);
      

  3.   


    float number=123.4567f;
    number.ToString(".##");//四舍五入
      

  4.   

    float x = 3.22232f;
    Console.WriteLine("{0:f2}",x);
      

  5.   

    float number=123.4567f;
    string value=number.ToString("F2");
      

  6.   

    double dubA = 100.7523450F;
    double dubB = dubB * 100;
    int intC = Convert.toInt32(dubB);
    dubA = Convert.toDouble(intC)/100.0F;