Reputation: 31
Double a = new BigDecimal(Double.valueOf(x))
.setScale(2,BigDecimal.ROUND_HALF_DOWN).doubleValue();
x
is of type Double
, which I cannot change..
Upvotes: 1
Views: 647
Reputation: 281446
Double.valueOf
takes a primitive double
and returns a boxed Double
, not the other way around. You're passing it a boxed Double
, so x
is autounboxed, then explicitly boxed by Double.valueOf
, then autounboxed again to pass it to new BigDecimal
. Just remove the valueOf
call:
Double a = new BigDecimal(x).setScale(2,BigDecimal.ROUND_HALF_DOWN).doubleValue();
This will autounbox x
once to pass it to the BigDecimal
constructor.
Upvotes: 2
Reputation: 17494
If x
is of type Double
, then Double.valueOf(x)
is the cause of the warning. Just write x
instead, which is already of the correct type.
Upvotes: 2