Re: [Quickfix-developers] QF java interface: conversion from double fields to BigDecimal give imprec
Brought to you by:
orenmnero
From: Oren M. <ore...@ya...> - 2003-05-14 14:52:05
|
A method like this already exists in the C++ API, it just needs to be wrapped in Java so you can access it. In the meantime can't you do something like this: BigDecimal number = new BigDecimal( Double.toString(doubleField.getValue()) ); Or do you still get a rounding error that way? Joerg Thoennes <Joe...@ma...> wrote: Hi all, 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. But to convert a QF java DoubleField into a BigDecimal I have to do the following: BigDecimal number = new BigDecimal( doubleField.getValue() ); Using this procedure, we get for e.g. 100.22 the BigDecimal value 100.219999999999998863131622783839702606201171875 which leads to errors at the exchange (invalid PRICE_STEP). A workaround would be to use rounding. I would prefer to have a way to get the underlying String representation of the DoubleField to hand it over to BigDecimal: BigDecimal number = new BigDecimal( doubleField.getStringValue() ); 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. Cheers, Jörg -- 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 ------------------------------------------------------- Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara The only event dedicated to issues related to Linux enterprise solutions www.enterpriselinuxforum.com _______________________________________________ Quickfix-developers mailing list Qui...@li... https://lists.sourceforge.net/lists/listinfo/quickfix-developers --------------------------------- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. |