How to convert String to Double

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chaitukdr
    New Member
    • Mar 2010
    • 2

    How to convert String to Double

    Hi,
    I tried to convert string value 1.10 to double like
    double val=convert.tod ouble("1.10");

    only 1.1 is given as result instead of 1.10
    plz suggest me with a proper answer
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    1.1 and 1.10 are equal. So is 1.10000
    TryParse
    Code:
    double d;           
    string s = Convert.ToString(Console.ReadLine());
    
     if (s != null)
                {
                    if (double.TryParse(s, out d))
                    {
                        Console.WriteLine(d.ToString());
    
                        if (d == 1.1000000)
                        {
                            Console.WriteLine("Equal");
                        }
                    }
                }

    Comment

    Working...