• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Problem ny using C # in Excel with Debug (xlw)


I have a problem : when I want to debug I type my function in an Excel cell which takes as parameters S,K,T,r and the market price. K=81,2(in one of my Excel cell) but when I add a breakpoint in my code in C# the value of K is 81,9999999999832 and not 81,2 like in Excel.

How can I fix the same value in C# and Excel please?
81.2 isn't possible to represent totally accurately as a double, Excel "knows" this when displaying numbers, in the debugger you see the actual representation of what is being stored to represent this. So basically what you're seeing is expected behaviour.



JohnAd is right -- it's an issue related to how floating-point numbers work. Read the Wikipedia article on 'IEEE-754' if you want to know all about it.

Alternatively, you can use the 'decimal' type when you really need the exact value. Operations on 'decimal' are much slower than those on 'double', so use it sparingly.