Is there any replacement of long double in java?

There is no straight replacement in Java.

You can use BigDecimal for this purpose.

You should understand that the bigger your double value is, the bigger lost of precision you will receive using it in your mathematical operations. BigDecimal helps you to aware this problem.

Here is code sample with BigDecimal:

String decimalString = "1423545135143513.523";
BigDecimal decimal = new BigDecimal(decimalString);

By this link you can find many examples with usage of BigDecimal class.


Though not a replacement, you can use java.lang.math.BigDecimal.You can roughly store billion of digits until you run out of memory. Its an arbitrary precision class, it will get as large as you'd like until your computer runs out of memory.

As per the documentation of BigDecimal:

Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a non-negative 32-bit integer scale, which represents the number of digits to the right of the decimal point. The number represented by the BigDecimal is (unscaledValue/10scale). BigDecimal provides operations for basic arithmetic, scale manipulation, comparison, hashing, and format conversion.

Tags:

C

Java