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 KevinWalker, Today, 07:48 PM
      0 responses
      3 views
      0 likes
      Last Post KevinWalker  
      Started by WaveAtElliot, Today, 05:11 PM
      1 response
      10 views
      1 like
      Last Post hdge4u
      by hdge4u
       
      Started by bosajin, Yesterday, 09:15 AM
      5 responses
      40 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by Dolfan, Today, 12:24 PM
      4 responses
      23 views
      0 likes
      Last Post NinjaTrader_Jim  
      Started by WeyldFalcon, Today, 11:09 AM
      7 responses
      30 views
      0 likes
      Last Post WeyldFalcon  
      Working...
      X