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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          153 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          89 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          133 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          127 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          107 views
          0 likes
          Last Post CarlTrading  
          Working...
          X