Skip to content

Files

Latest commit

 

History

History
14 lines (14 loc) · 925 Bytes

File metadata and controls

14 lines (14 loc) · 925 Bytes

The BigDecimal class is used to store decimal numbers with arbitrary precision (and the associated scale). With BigDecimal, you can store and compute numbers with the desired precision.

import java.math.BigDecimal;
public class Main {
    public static void main(String[] args) {
        BigDecimal a = new BigDecimal("3.14159265358979323846264338327950288419716939937510");
        System.out.println(a);
    }
}

Using Third-Party Libraries

Third-party libraries, such as Apache Commons Math, provide various functions for working with high-precision numbers.

Using Strings

Using strings to store high-precision numbers is generally not recommended. Strings are designed for storing text, and working with numbers in them can be difficult. Additionally, converting strings to numbers and vice versa can lead to precision loss and introduce complexities that programmers may struggle to manage effectively.