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 Taddypole, 04-26-2024, 02:47 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Eduardo  
        Started by futtrader, 04-21-2024, 01:50 AM
        6 responses
        58 views
        0 likes
        Last Post futtrader  
        Started by sgordet, Today, 11:48 AM
        0 responses
        4 views
        0 likes
        Last Post sgordet
        by sgordet
         
        Started by Trader146, Today, 11:41 AM
        0 responses
        5 views
        0 likes
        Last Post Trader146  
        Started by jpapa, 04-23-2024, 07:22 AM
        2 responses
        22 views
        0 likes
        Last Post rene69851  
        Working...
        X