Math, Parsing & BigDecimal in Java
From the Java cheat sheet · Math & Numbers · verified Jul 2026
Math, Parsing & BigDecimal
Common numeric operations and gotchas.
java
// Quick Reference
Math.max(3, 7); Math.abs(-5); Math.pow(2, 10);
Math.sqrt(16); Math.round(3.6);
int n = Integer.parseInt("42");💡 Floating-point math is inexact - use BigDecimal (from a String) for money.
⚡ Compare BigDecimals with compareTo(); equals() also checks scale (2.0 != 2.00).
📌 Integer.parseInt(s, radix) parses binary/hex/octal; parseInt throws on bad input.
🟢 Math.round returns long/int; Math.floor/ceil return double.
mathbigdecimalparsing