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 trilliantrader, 04-18-2024, 08:16 AM
    4 responses
    18 views
    0 likes
    Last Post trilliantrader  
    Started by mgco4you, Today, 09:46 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by wzgy0920, Today, 09:53 PM
    0 responses
    9 views
    0 likes
    Last Post wzgy0920  
    Started by Rapine Heihei, Today, 08:19 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by Rapine Heihei, Today, 08:25 PM
    0 responses
    10 views
    0 likes
    Last Post Rapine Heihei  
    Working...
    X