~/ learn/ java-from-zero/ cards/ BigDecimal & BigInteger — exact arithmetic
1 of 4

Type a BigDecimal addition from String constructors

Type a BigDecimal addition from String constructors

Answer

BigDecimal price = new BigDecimal("19.99"); BigDecimal tax = new BigDecimal("1.60"); BigDecimal total = price.add(tax);

String constructors preserve the exact decimal value. BigDecimal.add returns a new instance; BigDecimal is immutable.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/8fa37489-d406-4464-b339-c068afe9014a/flashcard utf-8 LF