Skip to content
Sharp

Core Java · interview question

In an e-commerce application, which data type is the most appropriate for storing a product's price when precise calculations involving currency are needed?

Multiple choiceMediumchapter-1-curatedpremiumcore-javavariables-and-data-types
Choose one answer
Answer and explanation

Correct answer

D. BigDecimal

Why

BigDecimal is preferred for monetary calculations to avoid the rounding errors associated with floating-point types like double. It provides precise control over decimal points, which is essential for financial calculations.

Test yourself on Core Java

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

Start free test
All Core Java questions →