Search code examples
c#.netstring-formattingscientific-notation

How to Convert The Display Format (Scientific notation to Double)


How to convert the scientific Notation in to Double..
Please kindly refer the image For your reference

enter image description here

on the header column i want to display the original "-" or "+" value i want to display not scientific notation how can i do this?
Coding Part

    private void clearAndLoadTree(AccountDetails account, TreeListNode parentNode)
    {
        treeDetails.Nodes.Clear();
        treeDetails.ClearNodes();
        populateTree(account, parentNode);
        treeDetails.ExpandAll();
    }

    private double populateTree(AccountDetails account, TreeListNode parentNode)
    {
        ArrayList al = new ArrayList();
        TreeListNode currentNode = addNode(account, parentNode);
        AccountDetails[] children = account.children;
        double lcValue = account.lcValue;
        if (children != null)
        {
            foreach (AccountDetails subAccount in children)
            {
                    lcValue += populateTree(subAccount, currentNode);
            }
        }

        currentNode.SetValue("lcValue", lcValue);
        return lcValue;
    }

    private TreeListNode addNode(AccountDetails account, TreeListNode parentNode)
    {
        TreeListNode node = treeAccount.AppendNode(null, parentNode);
        ******
        return node;
    }

Solution

  • This will do it.

    Double.Parse("-1.668E-04", NumberStyles.Float, CultureInfo.InvariantCulture);
    

    Edit

    sorry misunderstod you a little there. The above does not work on larger numbers so then you need to do this instead.

    var s = Double.Parse("-9.09494701772928E-13", NumberStyles.Float,CultureInfo.InvariantCulture);
    var b = s.ToString("F50").TrimEnd("0".ToCharArray());
    

    or

    string c = s.ToString("F50").TrimEnd('0')