You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/03/03 22:07:00 UTC

[jira] [Commented] (KAFKA-9642) "BigDecimal(double)" should not be used

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

ASF GitHub Bot commented on KAFKA-9642:
---------------------------------------

SoontaekLim commented on pull request #8212: KAFKA-9642: Change "BigDecimal(double)" constructor to "BigDecimal.valueOf(double)"
URL: https://github.com/apache/kafka/pull/8212
 
 
   https://issues.apache.org/jira/browse/KAFKA-9642
   for this reason, I modified the code that is using the "BigDecimal(double)" constructor.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> "BigDecimal(double)" should not be used
> ---------------------------------------
>
>                 Key: KAFKA-9642
>                 URL: https://issues.apache.org/jira/browse/KAFKA-9642
>             Project: Kafka
>          Issue Type: Bug
>            Reporter: Soontaek Lim
>            Assignee: Soontaek Lim
>            Priority: Minor
>
> I recommend not to use the BigDecimal(double) constructor. Because of floating point imprecision, we're unlikely to get the value we expect from that constructor.
> Instead, we should use BigDecimal.valueOf, which uses a string under the covers to eliminate floating-point rounding errors, or the constructor that takes a String argument.
>  
> From JavaDocs
> The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1) in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1), but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)