java:S2111 - "BigDecimal(double)" should not be used

Rule java:S2111 recommends this as a compliant solution:

double d = 1.1;
BigDecimal bd1 = BigDecimal.valueOf(d);

But the result isn’t precise when using

double d = 1.0000000000000001
BigDecimal bd1 = BigDecimal.valueOf(d); -> 1.0

The only compliant solution should be new BigDecimal(String)

Hey there.

I’ve moved your post to the category on reporting false-positives.

Specifically, we’re missing what version of SonarQube you’re using.