• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Floating point issue with simple price operations

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

    Floating point issue with simple price operations

    I'm having a weird floating point issue with a simple subtract operation between two EURUSD prices, that should give some number up to 5 significative decimals, yet it gives almost the right number but there's always a 0.0000000000x that pops up, and being this a simple add/subtract operation between two direct prices, I think it shouldn't give anything like this. I don't know if this feedback is useful for you but it's a heads up.

    In order to address it, which way would you suggest:

    1. Rounding float type ?

    or

    2. Using decimal types ?

    Update:
    Personal choice #1, it allows an easier writing and readable code
    Last edited by pstrusi; 09-20-2017, 08:22 AM.

    #2
    Hello pstrusi,

    Thank you for the post.

    Rounding the float will likely be the best thing to use. Using decimal will use an unnecessary amount of memory.

    I would advise using the following:

    Code:
    Round(Double, Int32)
    Here is a publicly available link to Round on the MSDN Documentation:
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Could you please post the code you are using to perform the subtraction operation?

    I look forward to your reply.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by GMiller64, Today, 01:13 PM
    3 responses
    7 views
    0 likes
    Last Post GMiller64  
    Started by itrader46, Today, 12:51 PM
    4 responses
    34 views
    0 likes
    Last Post itrader46  
    Started by hemlock, Today, 11:45 AM
    3 responses
    9 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by gbulle, Today, 11:31 AM
    2 responses
    8 views
    0 likes
    Last Post gbulle
    by gbulle
     
    Started by JPPoulin, Today, 10:43 AM
    6 responses
    25 views
    0 likes
    Last Post JPPoulin  
    Working...
    X