commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tommy Tynjä <to...@diabol.se>
Subject Re: [beanutils] Precision lost when converting BigDecimal
Date Wed, 01 Oct 2014 07:45:29 GMT
Hi.

Thank you for your feedback.

I've filed this issue as BEANUTILS-470 in JIRA.

Best regards,
Tommy Tynjä


> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message