API Support Forum
OEC API > API Support > C# double vs decimal. IMPORTANT!!!
Author Topic: C# double vs decimal. IMPORTANT!!!
(3 messages, Page 1 of 1)
Moderators: VPfau
eo707
Posts: 68
Joined: Nov 08, 2011


Posted: Jan 15, 2016 @ 09:24 AM             Msg. 1 of 3
Hello,
I would like to raise a subject that I think you should add to the FAQ page of yours.
What is best to use, decimal of double.
I saw in your components and library that you use double, for price..
I read on documentation that if you use it for calculations/money/market, then you should decimal....
Please make your suggestion..

In other hand, if I take your double, and set it to a variable of mine as decimal then I need to cast...

I wish that you will answer what is the best for C#.

This say, decimal:
http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when

That too suggest decimal for money/finance/market:
http://stackoverflow.com/questions/803225/when-should-i-use-double-instead-of-decimal

I wouldn't care to convert the entire application to one of each.
Note: when you set:
var p = 0.0;
You get a double, unless you cast.
C# can't do calculation with double vs decimal...use one type and calculate.

Please answer for all of C# developers..
Am looking forward to your deep suggestion..

Thank you for your API.
Developer.
NShine
Posts: 36
Joined:


Posted: Jan 19, 2016 @ 11:06 AM             Msg. 2 of 3
You are free to use the decimal type in your client applications, even though we send double values for prices. Our client applications are built to handle double values because we format displayed data to the needed precision. The issues brought up in the articles you posted come down to accumulation. If there is a place in your code where the errors in a double value will build up over time so your displayed value is affected, you will need to handle that. However, remember that you should be getting a lot of your data through updates, and these updates will replace the values you have saved. Therefore, there shouldn't be a risk for accumulation on your end for objects or information that can be requested/subscribed/updated through the API.
eo707
Posts: 68
Joined: Nov 08, 2011


Posted: Jan 19, 2016 @ 03:43 PM             Msg. 3 of 3
Is there any way to close the post?
My mark for a post that got an answer and is irrelevant is the fact that I am listed as the last one who wrote to it.
It is also an indication that the post did not get last reply..

The best solution is to allow us to mark a post as closed, or solved, etc....in order to disregard it.

If you do have this feature, please let me know.

Thank you in addition to allow me to test my application with my friend's demo.
running nice.

Thanks.