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

How to not display decimals

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

    How to not display decimals

    I have an indicator displaying 123.00 and I want it to just show 123

    Can anyone show me how to make a double convert to an integer, and ALSO display as an integer. (I have also tried the Convert.Int32 way of doing it and that had same results.) Right now it is:


    -Variables:
    private double cciValue = 0;

    -Performed every tick update after "Period" number of bars:
    cciValue = (int)cciData[0];

    -Down where it actually asks for it to display:
    graphics.DrawString(cciValue.ToString("f2"),


    Is there something different than "f2" that I can insert to try to make it display just the integer without decimals?
    I can't understand the syntax on the various websites that suggest {0:n} and the like.

    #2
    Sorry, would not know of the top of my head. I suggest consulting the Microsoft documentation on the ToString() method.

    Comment


      #3
      You can replace "f2" with "f0", or as you are using an integer I think you can try leaving the bracket empty .ToString()

      Comment


        #4
        Originally posted by LG View Post
        I can't understand the syntax on the various websites that suggest {0:n} and the like.
        I just posted this example elsewhere on the forums...

        Code:
        Print( String.Format( "High={0} Low={1} Open={2} Close={3}",
                               High[0], Low[0], Open[0], Close[0]
                            )
             );
        It shows some of the {0}, {1}, etc. syntax.

        The number in the curly braces is the number of the parameter to be substituted into the format string, so "{0}" gets replaced with the first parameter (in this case the value of High[0]) and the "{1}" gets replaced with the second parameter (Low[0]), etc.

        Note that the following will display the same output as the above example...

        Code:
        Print( String.Format( "High={3} Low={1} Open={2} Close={0}",
                               Close[0], Low[0], Open[0], High[0]
                            )
             );
        In addition, another entry can be made after the parameter number, which specifies the way the parameter gets formatted. I'm not good at this part, and have to look it up every time I use it, but here are a couple of examples of what I've used in the past...

        Code:
        Print( String.Format( "Bar={0:D2} Close={3:F2} Value={4:F2} Cur={1:F2} Last={2:F2}",
                               CurrentBar, Cur, Last, Close[0], Value[0]) );
        
        (Note the above parameters are out of order... I must have decided to insert something in the middle of the format string and didn't want to renumber everything.)
        The "D2" means display as an integer string (no decimal point) of at least 2 digits, and "F2" means a fixed point string with two decimal places.

        There are lots of other variations that can be used.

        Here are a couple of links to some MSDN .NET documentation that tells lots more: http://msdn.microsoft.com/library/de...matstrings.asp, http://msdn2.microsoft.com/en-us/library/txafckwd(vs.71).aspx

        Although you may find the following references more readable:



        Comment


          #5
          Originally posted by LG View Post
          -Down where it actually asks for it to display:
          graphics.DrawString(cciValue.ToString("f2"),
          Actually, I already found the simple solution to this. I changed "f2" to "f0" and it displays as an integer without decimals. Thanks for helping, though!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Irukandji, Yesterday, 02:53 AM
          2 responses
          17 views
          0 likes
          Last Post Irukandji  
          Started by adeelshahzad, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post adeelshahzad  
          Started by CortexZenUSA, Today, 12:53 AM
          0 responses
          3 views
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Working...
          X