[ 
https://issues.apache.org/jira/browse/BEANUTILS-470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14156167#comment-14156167
 ] 

Tommy Tynjä commented on BEANUTILS-470:
---------------------------------------

[~mgainty]: Test cases passes for BigDecimal to BigDecimal conversion in our 
environments but fails for classes extending BigDecimal, which was discovered 
since that was our use case.

[[email protected]]: Thank you! I would very much appreciate to be 
included in the contributors section and to be marked as the assignee for this 
task. More importantly, when can this issue be released? Is there any schedule 
for 1.9.3?

> Precision lost when converting BigDecimal
> -----------------------------------------
>
>                 Key: BEANUTILS-470
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-470
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: ConvertUtils & Converters
>    Affects Versions: 1.9.2
>         Environment: java version "1.7.0_51"
> Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
> Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)
>            Reporter: Tommy Tynjä
>             Fix For: 1.9.3
>
>         Attachments: NumberConverter_BigDecimal_precision_loss_fix.patch, 
> TestCase_ExtendingBigDecimal.patch
>
>
> When converting a domain specific object which extends BigDecimal to a 
> regular java.math.BigDecimal, 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 (in the current trunk). 
> I've created a reproducing test case which demonstrates the behavior (please 
> see attached patch file).
> Adding the following code to NumberConverter where targetType equals 
> BigDecimal seems to fix this issue (and all project test cases pass):
> else if (value instanceof BigDecimal) { return targetType.cast(new 
> BigDecimal(value.toString())); }
> Adding an attachment containing a patch for the propsed solution.
> Filing this bug after receiving feedback on user mailing list:
> http://mail-archives.apache.org/mod_mbox/commons-user/201409.mbox/raw/%3C542B059C.40901%40oliver-heger.de%3E/



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to