Skip to content
Sharp

Core Java · interview question

How can you convert a double to a BigDecimal in Java correctly?

Multiple choiceMediumchapter-1-curatedpremiumcore-javanumeric-types-and-money-basics
Choose one answer
Answer and explanation

Correct answer

D. BigDecimal.valueOf(double)

Why

Using BigDecimal.valueOf(double) is the correct way to convert a double to BigDecimal, as it helps avoid precision loss that could occur with new BigDecimal(double).

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →