Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using ToString() to format scientific notation...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using ToString() to format scientific notation...

    I'm getting the return from Slope() which is a double and expressed as scientific notation.
    For example:

    double myRes = Slope(blah, blah);

    printing myRes displays -> 2.249999999999984E-06

    I would like to display/format myRes like this:

    2.24 or maybe 2.249. etc.

    Problem is when I do this:

    myRes.ToString("0.00");

    I get -> 0.00

    This approach seems to work in other situations, why not here?

    #2
    Try this:

    myRes.ToString("N4")

    If it's an indicator output and you want more decimal places on your chart, you need to override FormatPriceMarker:

    public override string FormatPriceMarker(double price)
    {
    return price.ToString("N4"); //Formats price values to 4 decimal places
    }

    Comment


      #3
      Thank you , that worked, however...

      I'm getting 0.0001 as a result from 0.000132249999228991, which is to be expected. In this instance, the number is useless to me. How can I turn that into say 1% or where I can use it as -1%, 1%, 1.5% etc.

      Comment


        #4
        Try something like

        myRes.ToString("#0.0000 %")


        Learn how to create a custom numeric format string to format numeric data in .NET. A custom numeric format string has one or more custom numeric specifiers.

        Comment


          #5
          Ok, this is what I got going on...

          -- The '\u2030' -> read on:

          Learn how to create a custom numeric format string to format numeric data in .NET. A custom numeric format string has one or more custom numeric specifiers.


          string fmt = "#0.## "+'\u2030';

          myRes * 1000;

          myRes.ToString(fmt);

          This gives me:

          6.5% from 6.49999999...E-06

          It's a number that I can use, and means something to me however 'un-mathematically' perfect it may be.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          581 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          338 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X