Skip to content
Sharp

Core Java · interview question

You need to store and calculate prices with high precision. Which data type should you choose and why?

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

Correct answer

D. BigDecimal, for precision

Why

BigDecimal is designed for precise calculations, such as those involving currency, as it avoids the precision errors associated with floating-point types like 'double'. 'int' and 'long' do not support decimal values, and 'double' may introduce rounding errors.

Test yourself on Core Java

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

Start free test
All Core Java questions →