大家好,刚才写了一个代码,但是最后结果小数被四射五入成一位了,既:1.1  正常的是:1.083 应该怎么能显示正确啊? string[] line1 = line.Split('|');
 String line5 = line1[3].ToString();
 float.TryParse(line5.ToString(), out f);
 f1 = f1 + (f / 100);
 this.label1.Text = f1.ToString();

解决方案 »

  1.   

    应该是你数据类型不对,f1是什么数据类型呀。你要单纯保留小数位可以f1.ToString(“9999999.99”)
      

  2.   

    double x = double.Parse("");
      double y = x % 0.01;
      double z = x - y;
      

  3.   

    this.label1.Text = f1.ToString("F2");
      

  4.   

    double d=659898.518621;
    double result = Math.Round(d,2);
      

  5.   

    f1=Math.Round(f1, 2, MidpointRounding.AwayFromZero);
      

  6.   

    Math.Round(f1, 3).ToString()//其中你想保留几位小数“3”那个位置你写几就行了。F1是你要操作的数据
      

  7.   

    默认的舍入方式是偏向偶数的,习惯上的四舍五入后面要加点东西
    Math.Round(f1, 2, MidpointRounding.AwayFromZero);
      

  8.   

     string[] line1 = line.Split('|');
     String line5 = line1[3].ToString();
     float.TryParse(line5.ToString(), out f);
     f1 = f1 + (f / 100);
     this.label1.Text = f1.ToString("0.00");
    这样就行啦,有那么麻烦嘛
      

  9.   

    this.label1.Text = f1.ToString("f2");
    这样好象成的了
      

  10.   

    试一下吧,Math.Round函数,可以查查MSDN的
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Xml;
    using System.Collections;namespace ConsoleApplication1
    {
        class Program
        {        public Program()
            {
                double s = 1.555;
                Console.WriteLine( Math.Round(s, 2) );
            }        static void Main(string[] args)
            {
                Program p1 = new Program();
                Console.ReadLine();
            }
        }
    }