Question

How do I use really large numbers in Java?

Answer

There are many classes of applications that require support for large numbers. When primitive data types like long, and double just won't cut it, Java offers an answer in the form of the java.math package.

Whether its whole numbers or decimals you need, java.math has the solution. For whole numbers, use the BigInteger class, and for fractions use the BigDecimal class. Each allows a wide range of mathematical operations, from simple things like addition, subtraction, multiplication and division to more complex operations like logical AND, OR, NOT and powers.


Back