none
Converting a double to string RRS feed

  • Question

  • How can we convert a double to a string without changing the format?
    For e.g. i have a double value .0000565.
    I want to covert this to ".0000565".
    My code is:
    double d = .0000565;
    string str = d.tostring("0.00000000");
    but i am getting str = "5.65E-05",
    but i need "0.0000565".
    Please help
    Thursday, November 8, 2012 8:44 AM

Answers

  • You can use #.### but you still have to decide how much precision is enough.

    double d1 = 0.065;
    double d2 = 0.000000056556;
    double d3 = 0.00000000000056556;
    
    Console.WriteLine(d1.ToString("#.############"));
    Console.WriteLine(d2.ToString("#.############"));
    Console.WriteLine(d3.ToString("#.############"));
    

    This signature unintentionally left blank.

    • Marked as answer by Chethan Jain Friday, November 9, 2012 3:42 AM
    Thursday, November 8, 2012 11:34 AM

All replies

  • Hi,

    Try this,

    double d = .0000565;
    string str = d.tostring("0.0000000");


    PS.Shakeer Hussain

    Thursday, November 8, 2012 9:05 AM
  • I am doing the Same
    My req if the value is .0056 i want  string str =".0056"
                                      .000000056556 = ".000000056556"

    how can we achieve this?

    Thursday, November 8, 2012 9:34 AM
  • You can use #.### but you still have to decide how much precision is enough.

    double d1 = 0.065;
    double d2 = 0.000000056556;
    double d3 = 0.00000000000056556;
    
    Console.WriteLine(d1.ToString("#.############"));
    Console.WriteLine(d2.ToString("#.############"));
    Console.WriteLine(d3.ToString("#.############"));
    

    This signature unintentionally left blank.

    • Marked as answer by Chethan Jain Friday, November 9, 2012 3:42 AM
    Thursday, November 8, 2012 11:34 AM
  • Thanks a lot.It works.
    Friday, November 9, 2012 3:42 AM