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 FrancisMorro, Today, 03:24 AM
      0 responses
      2 views
      0 likes
      Last Post FrancisMorro  
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,770 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      31 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      945 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      11 views
      0 likes
      Last Post Max238
      by Max238
       
      Working...
      X