本帖最后由 yinqiuyan 于 2010-07-16 15:03:30 编辑

解决方案 »

  1.   

    string price = "1.00";
    string[] strs = price.split('.');
    if(strs[1]=="00")
       price = strs[0];
    LZ可以把price换成别的价格试试
      

  2.   

                Double d = 1.00;
                String s = d.ToString().TrimEnd('0');
                if (s.EndsWith("."))
                    s = s.Substring(0, s.Length - 1);
                Console.WriteLine(s);
      

  3.   

    没有直接格式化的函数吗?VB中有Format(string1,“#0.00”)但是在C#中不知怎么弄
      

  4.   

                double price = 1.00;
                double price2 = 0.5;
                Console.WriteLine(price.ToString());
                Console.WriteLine(price2.ToString());
                Console.ReadLine();
    用double接受OK了.
      

  5.   

    如果是string类型就这样:
                string price = "1.00";
                string price2 = "0.5";
                Console.WriteLine(Double.Parse(price));
                Console.WriteLine(Double.Parse(price2));
                Console.ReadLine();
      

  6.   

    private string GetPrice(double arg)
    {
       string price = arg.ToString();
       string[] strs = price.split('.');
       if(strs[1]=="00")
          price = strs[0];
       return price;
    }
     直接复制过去用吧
      

  7.   

    我的本来是double 类型,要变成 string 类型,那是商品的单价,客户要求有小数的带着小数,没有的不要小数,请问该怎么实现啊?
      

  8.   

    直接ToString()不就完了
    double num=1.0;
    string numS1=num.ToString();num=0.5;
    string numS2=num.ToString();Console.WriteLine(numS1);
    Console.WriteLine(numS2);
      

  9.   

    为什么我的代码里,就是楼主要求的那样子?
                double d1 = 1.00, d2 = 0.5;            Console.WriteLine("{0}       {1}",d1,d2);
      

  10.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace Test
    {
        class Program
        {
            static void Main(string[] args)
            {
                double price = 1.00;
                double price2 = 0.5;            print(price);
                print(price2);
                Console.ReadLine();
            }        static void print(double price)
            {
                if ((price - (Int32)price) == 0)
                {
                    Console.WriteLine((Int32)price);
                }
                else
                {
                    Console.WriteLine(price);
                }
            }
        }
    }
      

  11.   

    你用substring截取“.00”不就可以了
      

  12.   

    谢谢大家,结贴,我还是用7楼的解决办法了,用Double.Parse(price.tostring())有时候1.00会变成1.0,打印出来就成了10,所以我还是分开了 点后的判断了,