Re: [Quickfix-developers] QF java interface: conversion from double fields to BigDecimal give impre
Brought to you by:
orenmnero
From: Joerg T. <Joe...@ma...> - 2003-09-01 14:29:38
|
Hello Oren, I wonder how the method is called which enables me to directly set the=20 String value of a DoubleField. Does version 1.6.0 include this method=20 also for the Java API? Thanks, J=F6rg > A method like this already exists in the C++ API, it just needs to be=20 > wrapped in Java so you can access it. In the meantime can't you do=20 > something like this: > =20 > BigDecimal number =3D new BigDecimal(=20 > Double.toString(doubleField.getValue()) ); >=20 > Or do you still get a rounding error that way? >=20 > */Joerg Thoennes <Joe...@ma...>/* wrote: >=20 > Hi all, >=20 > we got a problem with the conversion of double fields to Java > BigDecimal. We actually use > the BigDecimal class to represent values with fractional parts to > avoid nasty rounding problems > with floating point values. >=20 > But to convert a QF java DoubleField into a BigDecimal I have to do > the following: >=20 > BigDecimal number =3D new BigDecimal( doubleField.getValue() ); >=20 > Using this procedure, we get for e.g. >=20 > 100.22 the BigDecimal value > 100.219999999999998863131622783839702606201171875 >=20 > which leads to errors at the exchange (invalid PRICE_STEP). A > workaround would be to use > rounding. >=20 > I would prefer to have a way to get the underlying String > representation of the DoubleField to > hand it over to BigDecimal: >=20 > BigDecimal number =3D new BigDecimal( doubleField.getStringValue() = ); >=20 > This method should be in the Field base class and be available for > all data types. > I think the same would be also make sense for the C++ and the other > APIs. >=20 > Cheers, J=F6rg >=20 > --=20 > Joerg Thoennes > http://macd.com > Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH > Fax : +49 (0)241 44597-10 LLothringer Str. 52, D-52070 Aachen >=20 >=20 >=20 > ------------------------------------------------------- > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Cla= ra > The only event dedicated to issues related to Linux enterprise solu= tions > www.enterpriselinuxforum.com >=20 > _______________________________________________ > Quickfix-developers mailing list > Qui...@li... > https://lists.sourceforge.net/lists/listinfo/quickfix-developers >=20 > -----------------------------------------------------------------------= - > Do you Yahoo!? > The New Yahoo! Search=20 > <http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com> -=20 > Faster. Easier. Bingo.) --=20 Joerg Thoennes http://macd.com Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen |