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

  • Thread starter Thread starter MattX
  • Start date Start date
Joined
11/14/12
Messages
2
Points
11
Hi

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.

John
 
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.
 
Back
Top Bottom