Announcement

Collapse
No announcement yet.

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

    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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        90 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        137 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        120 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        71 views
        0 likes
        Last Post PaulMohn  
        Working...
        X