NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-14-2008, 09:56 PM   #1
LG
Senior Member
 
Join Date: Jul 2006
Location: Los Angeles, California, USA
Posts: 136
Thanks: 0
Thanked 0 times in 0 posts
Default 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.
LG is offline  
Reply With Quote
Old 04-14-2008, 10:10 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Sorry, would not know of the top of my head. I suggest consulting the Microsoft documentation on the ToString() method.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-15-2008, 09:41 AM   #3
MJT
Senior Member
 
Join Date: Jun 2006
Posts: 111
Thanks: 0
Thanked 1 time in 1 post
Default

You can replace "f2" with "f0", or as you are using an integer I think you can try leaving the bracket empty .ToString()
MJT is offline  
Reply With Quote
Old 04-18-2008, 02:01 PM   #4
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Quote:
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:

http://blog.stevex.net/index.php/str...ing-in-csharp/
http://blogs.msdn.com/kathykam/archi...29/564426.aspx
http://idunno.org/archive/2004/14/01/122.aspx
KBJ is offline  
Reply With Quote
Old 04-18-2008, 02:04 PM   #5
LG
Senior Member
 
Join Date: Jul 2006
Location: Los Angeles, California, USA
Posts: 136
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
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!
LG is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Visually display Bid/Ask sbgtrading NinjaScript File Sharing Discussion 5 06-18-2008 03:17 PM
How to display Bid/Ask on the Y axis asalada Miscellaneous Support 1 04-10-2008 04:51 AM
FX Entry Decimals trader2be Connecting 2 12-13-2007 09:24 PM
Column Display Ronin Market Analyzer 4 09-07-2007 01:51 PM
fractions/decimals Gar Miscellaneous Support 3 05-24-2005 03:07 AM


All times are GMT -6. The time now is 06:39 AM.