[Quickfix-developers] QF java interface: conversion from double fields to BigDecimal give imprecise
Brought to you by:
orenmnero
From: Joerg T. <Joe...@ma...> - 2003-05-14 14:24:17
|
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 |