Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Math issue dividing an integer

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

    Math issue dividing an integer

    OK, here's my issue. I have an integer value that I want to divide by 100 and assign the results to a double. e.g. below:
    int iIntValue;
    double dOrderPrice;
    double dResult;

    iIntValue = 20;
    dOrderPrice = Position.AveragePrice;
    dResult = dOrderPrice - (iIntValue / 100);

    When I do a Print(dOrderPrice + " : " +dResult + " : " +iIntValue);
    I get:
    87.69 : 0 : 20
    when I expect to get:
    87.69 : 0.2 : 20

    I should be able to divide an integer and get a double. Is there a reason that this math would not work?

    #2
    Hi, thanks for posting. You should cast the 100 to a double ((double)100) or add a .0 to the end of the value to make it a double and iIntValue should also be a double. It will truncate the fractional value if you use an integer.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I did a work around by assigning the int value to a local double variable and then dividing by 100.
      I have not seen this behavior before.

      Comment


        #4
        Thank you for the feedback. I verified it does the same in Visual Studio for C#. Apparently I don't code enough C# to notice.

        Closed.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by geddyisodin, 04-25-2024, 05:20 AM
        8 responses
        58 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        4 responses
        3,285 views
        1 like
        Last Post jgualdronc  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        5 views
        0 likes
        Last Post Option Whisperer  
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        22 views
        0 likes
        Last Post halgo_boulder  
        Started by mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Working...
        X