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, 09: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:
    Rounds a value to the nearest integer or to the specified number of fractional digits.


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

    I look forward to your reply.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    89 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    57 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    119 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    195 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    176 views
    0 likes
    Last Post CarlTrading  
    Working...
    X