...
Code Block | ||
---|---|---|
| ||
// printsPrints 0.1000000000000000055511151231257827021181583404541015625 // when run in FP-strict mode System.out.println(new BigDecimal(0.1)); |
...
This compliant solution passes the decimal literal as a String
so that the BigDecimal(String val)
constructor is invoked and the precision is preserved.:
Code Block | ||
---|---|---|
| ||
// printsPrints 0.1 // when run in FP-strict mode System.out.println(new BigDecimal("0.1")); |
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
NUM10-J | lowLow | probableProbable | lowLow | P6 | L2 |
Automated Detection
Automated detection is straightforward.
...
[JLS 2005] | |
[Seacord 2015] | NUM10-J. Do not construct BigDecimal objects from floating-point literals LiveLesson |
...