Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 PaulMohn, Today, 05:00 AM
          0 responses
          8 views
          0 likes
          Last Post PaulMohn  
          Started by ZenCortexAuCost, Today, 04:24 AM
          0 responses
          6 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by ZenCortexAuCost, Today, 04:22 AM
          0 responses
          3 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by SantoshXX, Today, 03:09 AM
          0 responses
          16 views
          0 likes
          Last Post SantoshXX  
          Started by DanielTynera, Today, 01:14 AM
          0 responses
          5 views
          0 likes
          Last Post DanielTynera  
          Working...
          X