Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Math.Truncate inconsistencies

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

    Math.Truncate inconsistencies

    I'm having an issue with Math.Truncate. Is anyone able to explain why

    Math.Truncate(1.32960*10000) returns 13295

    but

    Math.Truncate(13296.0) returns 13296

    And note that

    Math.Truncate(1.32980*10000) correctly returns 13298


    #2
    Hi mbell.irves, thanks for your question.

    I'm not sure exactly why that happens. You would need to know exactly how the compiler works to know why you get precision loss here. It might be because its considering 10000 to be an integer, but I am not sure.

    Best regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hi mbell.irves, thanks for your question.

      I'm not sure exactly why that happens. You would need to know exactly how the compiler works to know why you get precision loss here. It might be because its considering 10000 to be an integer, but I am not sure.

      Best regards.
      Ok, that's fine. It's odd but I worked around it by now always adding a very small decimal to the price after multiplying it up and that seems to do the trick. Thanks the for taking the time to answer.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ct, 05-07-2023, 12:31 PM
      6 responses
      202 views
      0 likes
      Last Post wisconsinpat  
      Started by kaywai, Today, 06:26 AM
      0 responses
      1 view
      0 likes
      Last Post kaywai
      by kaywai
       
      Started by kevinenergy, 02-17-2023, 12:42 PM
      118 responses
      2,778 views
      1 like
      Last Post kevinenergy  
      Started by briansaul, Today, 05:31 AM
      0 responses
      9 views
      0 likes
      Last Post briansaul  
      Started by traderqz, Yesterday, 12:06 AM
      11 responses
      28 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X