Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Casting a DOUBLE into an Int and get the Last Number of Decimal

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

    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 Files

    #2
    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.
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    80 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X