float f1 ,result;
得到小数点前一位:
string sum;
float[] f2;
f1= 2012.111;
f2 = f1.Split('.');
sum= right(f2[0].tostring(),1);
sum = sum + "." + f2[1].tostring();
result = float.parse(sum);最后result就等于2.111
同理你也可以得到小树点后一位

解决方案 »

  1.   

    to
    一个float类型,我如何得到小数前一位和小数后的值。
    如:2012.12f  我想得到2.12f
    该怎么做·--------
    using System;public class Testfloat
    {
    public Testfloat()
    {
    float a=212.12f;
    string b=a.ToString();
    int a1=b.IndexOf(".");
    Console.WriteLine(b.Substring(a1-1));
    }

    public static void Main()
    {
    new Testfloat();
    }
    }
    }
      

  2.   

    using System;
    using System.IO;public class Testfloat
    {
    public Testfloat()
    {
    //File.Create("dd.dbf");
    float f1 = 2012.12f;
    string str =  f1.ToString().Substring(f1.ToString().IndexOf('.') - 1);
    Console.WriteLine(str);
    Console.WriteLine(Single.Parse(str));
    }

    public static void Main()
    {
    new Testfloat();
    }

    }
      

  3.   

    float f = 2012.12f;
    f = f % 10;
    MessageBox.Show(f.ToString());怎么我又没分的啦,还是我写的太少了?:P