API Support Forum
OEC API > API Support > PriceToString StringToPrice round-tripping with comma decimal
Author Topic: PriceToString StringToPrice round-tripping with comma decimal
(4 messages, Page 1 of 1)
Moderators: VPfau
jlanawalt
Posts: 88
Joined: Feb 12, 2009


Posted: Dec 10, 2012 @ 07:32 PM             Msg. 1 of 4
We have a customer in Europe who's computer is set to their expected locale with the comma as a decimal. We have found that the PriceToString and StringToPrice functions do not round-trip the same values when working with contracts that have a fractional format, like grain options (eg "OZCF3 C7,4")

Given the following C++ code:


_bstr_t constr("OZCF3 C7,4");
OECAPICOM::IContractPtr con = OECAPI()->Contracts->Item(constr);
if(con) {
_bstr_t string("0.06 7");
double price = con->StringToPrice(string);
_bstr_t string2 = con->PriceToString(price);
double price2 = con->StringToPrice(string2);
_bstr_t string3 = con->PriceToString(price2);
}


These are our outputs:
string {"0.06 7" (1)} _bstr_t
price 6.0087500000000000 double
string2 {"6.00 7" (1)} _bstr_t
price2 600.00874999999996 double
string3 {"600.00 7" (1)} _bstr_t


See how the value increases from 0.06 to 600.00.

We can attempt to correct for this by replacing the decimal with a comma:


_bstr_t constr("OZCF3 C7,4");
OECAPICOM::IContractPtr con = OECAPI()->Contracts->Item(constr);
if(con) {
_bstr_t string("0,06 7");
double price = con->StringToPrice(string);
_bstr_t string2 = con->PriceToString(price);
}

string {"0,06 7" (1)} _bstr_t
price 0.068750000000000006 double
string2 {"0.06 7" (1)} _bstr_t


When we work with non-fractional values this drift does not happen. Also we find it interesting that while the parsing expects a comma, the string formatting does not produce one.
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Dec 11, 2012 @ 08:29 AM             Msg. 2 of 4
We will check it, thank you!

Victor Vins
Lead Software Developer
jlanawalt
Posts: 88
Joined: Feb 12, 2009


Posted: Dec 13, 2012 @ 05:54 PM             Msg. 3 of 4
Do you imagine it would be a server-side or client library fix? We can code a work-around but would like to have some idea if a fix will cause our work-around to cause problems requiring another update on our end.

Thank you,
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Dec 14, 2012 @ 08:17 AM             Msg. 4 of 4
It will be a client-side update

Victor Vins
Lead Software Developer