NO IMAGE

 

1.只要求保留N位不四捨五入

        float f = 0.55555f;
        int i =(int)(f * 100);
        f = (float)(i*1.0)/100;

2.保留N位,並且四捨五入    

        decimal d= decimal.Round(decimal.Parse(“0.55555”),2);

3.保留N位,並且四捨五入

        Math.Round(0.55555,2)

4.保留N位,並且四捨五入

        double dbdata = 0.55555;
        string str1 = dbdata.ToString(“f2”);//fN 保留N位,四捨五入

5.保留N位,並且四捨五入

        string result = String.Format(“{0:N2}”, 0.55555);//2位
        string result = String.Format(“{0:N3}”, 0.55555);//3位

6.保留N位,並且四捨五入

        double s=0.55555;
        result=s.ToString(“#0.00”);//點後面幾個0就保留幾位

或者(求圓的面積和周長)

                double s = Convert.ToDouble(textBox1.Text);
                double mianji = Math.PI * s * s;
                textBox2.Text = mianji.ToString(“F3”);
                double zhouchang = 2 * Math.PI * s;
                textBox3.Text = zhouchang.ToString(“F3”);