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 kinfxhk, 07-13-2026, 10:18 AM
    0 responses
    24 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 09:50 AM
    0 responses
    14 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 07:21 AM
    0 responses
    21 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-11-2026, 02:11 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    135 views
    0 likes
    Last Post SalmaTrader  
    Working...
    X