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 NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X