Thursday, 5 September 2013

Conversion from string to double - Possibility and errors

Conversion from string to double - Possibility and errors

I am aware that the string 2.34 would never be equal to the double 2.34.
No matter what library or algorithm you tried (lexical_cast,atof). Also
2.3400 can not be represented as double type. Instead it will be equal to
2.3399999999999999 . A little background I am working on an application
that passes of values to an external application using its api. Think of
it as some sort of a trading application. The user can pass values using
the applications api or the user can pass value by using the application
directly.Now when the user uses the application directly and the user
types in 2.34 the value is processed as 2.34 however when I use the API
which requires double as a parameter I pass 2.34 and it passes of as
2.3399999999999999 which is not acceptable. My question is how would the
application be handling this and is there a way to store 2.34000.. in a
double ?

No comments:

Post a Comment