commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [beanutils] Precision lost when converting BigDecimal
Date Tue, 30 Sep 2014 19:33:48 GMT
Hi,

Am 30.09.2014 um 09:26 schrieb Tommy Tynjä:
> Hi.
> 
> I'm using commons-beanutils in my current project for bean copy
> operations. I have a use case where I would like to convert a domain
> specific object which extends BigDecimal to a regular
> java.math.BigDecimal. If my domain specific object contains decimals,
> precision is lost at time of conversion. A BigDecimal of e.g. value
> 3200.11 will be converted to a BigDecimal with value 3200. This happens
> due to org.apache.commons.beanutils.converters.NumberConverter does a
> BigDecimal.valueOf(value.longValue()) at line 375 (current trunk). I've
> created a reproducing test case which demonstrates the behavior (please
> see the attached TestCase_ExtendingBigDecimal.patch file).
> 
> Is this a bug or how am I expected to handle this use case?
> 
> Adding the following code (please see attached NumberConverter.patch
> file) before executing "else { return
> targetType.cast(BigDecimal.valueOf(value.longValue())); }" in
> NumberConverter seems to fix this issue (and all project test cases pass):
> } else if (value instanceof BigDecimal) {
> return targetType.cast(value);
> }

this is probably a bug. The best way to go is opening a new ticket in
Jira [1] describing the problem. Please attach your unit test and your
proposed patch.

Thanks!
Oliver

> 
> Best regards
> Tommy Tynjä
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message