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 zstheorist, Today, 07:52 PM
      0 responses
      3 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      149 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Working...
      X