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 > Application Technical Support > Miscellaneous Support > Historical Version 7 Beta Threads > Version 7 Beta General Questions & Bug Reports

Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports.

 
 
Thread Tools Display Modes
Old 11-30-2010, 09:37 AM   #1
m. khalid
Junior Member
 
Join Date: Jun 2010
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Casting a DOUBLE into an Int and get the Last Number of Decimal

Hi,
(1) I'd like to get the last number of decimal (for example : if hh = 1.3257, I'd like to register an integer of 7).
(2) I've done the following but found out that after casting into an integer( vb ), the last digit was not the same and ended up I was getting the wrong value ( vc ). May I know where I've made mistakes? Thanks!

if(Bars.FirstBarOfSession)

{
hh = High[0];
}

double va = hh*10000;
int vb = (int) va;
int vc = vb % 10;

Print(hh.ToString("0.0000") + " " + va.ToString("00000") + " " + vb.ToString("00000") + " " + vc.ToString("0"));
Attached Images
File Type: jpg casting.JPG (39.2 KB, 4 views)
m. khalid is offline  
Old 11-30-2010, 09:54 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello m. khalid,

This is more C# related so beyond our scope of support.

To get the integer portion of a double value, you may want to use Math.Truncate() rather than casting it as integer.
http://msdn.microsoft.com/en-us/libr...(v=VS.90).aspx
NinjaTrader_RyanM is offline  
 

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
Help to convert from double to int safetrading Indicator Development 6 09-30-2010 09:46 PM
ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double s adamus Version 7 Beta General Questions & Bug Reports 9 06-28-2010 04:16 PM
Double into int Gepetto Automated Trading 5 11-18-2009 11:16 AM
casting a string to an int blarouche Indicator Development 1 07-10-2009 11:14 AM
double to int ? zoltran Indicator Development 3 03-14-2007 01:51 AM


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