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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    598 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    557 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X