Skip to content
Sharp

Core Java · interview question

When storing a monetary value in a BigDecimal, what is a recommended best practice to avoid precision issues?

Multiple choiceMediumchapter-7-curatedpremiumcore-javabigdecimal-and-money
Choose one answer
Answer and explanation

Correct answer

B. Use a String to initialize the BigDecimal.

Why

Initializing a BigDecimal with a String ensures that the value is exactly represented, avoiding the precision issues associated with floating-point types.

Test yourself on Core Java

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

Start free test
All Core Java questions →