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 kschuble, Today, 01:16 PM
      0 responses
      7 views
      0 likes
      Last Post kschuble  
      Started by wooofad, Today, 11:34 AM
      0 responses
      13 views
      0 likes
      Last Post wooofad
      by wooofad
       
      Started by tonynt, Today, 10:06 AM
      1 response
      18 views
      0 likes
      Last Post bltdavid  
      Started by Kediil, Yesterday, 09:26 AM
      2 responses
      30 views
      0 likes
      Last Post Kediil
      by Kediil
       
      Working...
      X