Decimal numbers cannot be precisely represented as a BigDecimal
if the BigDecimal(double val)
constructor is used. The primitive type double
cannot precisely represent all decimal fractions, because its underlying representation is binary. Consequently, the input to the BigDecimal(double val)
constructor can lose precision before the constructor is ever invoked.
Noncompliant Code Example
...
Risk Assessment
Using the BigDecimal
constructor that accepts decimal literals can lead (double val)
constructor with decimal floating point literals leads to loss of precision.
Guideline | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
FLP08-J | low | probable | low | P6 | L2 |
Automated Detection
TODOAutomated detection appears to be straightforward.
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this guideline on the CERT website.
...