Skip to content
Sharp

Core Java · interview question

Which method would you use to ensure a BigDecimal representing money is rounded to two decimal places using half-up rounding?

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

Correct answer

B. SetScale(2, RoundingMode.HALF_UP)

Why

The setScale method adjusts the scale of a BigDecimal and applies the specified rounding mode, which is crucial for rounding monetary values to the nearest cent.

Test yourself on Core Java

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

Start free test
All Core Java questions →