BigDecimal longValue() Method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The java.math.BigDecimal.longValue() is an in-built function which converts this BigDecimal to a long value. This function discards any fractional part of this BigDecimal. The function returns only the lower-order 64 bits when the result of the conversion is too big to be represented as a long value. Syntax: public long longValue() Parameters: This function accepts no parameters. Return Value: This function returns the long value of this BigDecimal. Examples: Input : 1987812456121.176 Output : 1987812456121 Input : "721111" Output : 721111 Below programs illustrate the use of java.math.BigDecimal.longValue() method: Program 1: Java // Java program to illustrate // longValue() method import java.math.*; import java.io.*; class GFG { public static void main(String[] args) { // Creating 2 BigDecimal Objects BigDecimal b1, b2; // Assigning values to b1, b2 b1 = new BigDecimal("1987812456121.176"); b2 = new BigDecimal("721111"); // Displaying their respective Long Values System.out.println("The Long Value of " + b1 + " is " + b1.longValue()); System.out.println("The Long Value of " + b2 + " is " + b2.longValue()); } } Output: The Long Value of 1987812456121.176 is 1987812456121 The Long Value of 721111 is 721111 Note: Information regarding the overall magnitude and precision of large this BigDecimal values might be lost during the course of conversion by this function. As a consequence, a result with the opposite sign might be returned. Program 2: Below program illustrates a scenario when the function returns a result with the opposite sign. Java // Java program to illustrate // longValue() method import java.math.*; import java.io.*; class GFG { public static void main(String[] args) { // Creating 2 BigDecimal Objects BigDecimal b1, b2; // Assigning values to b1, b2 b1 = new BigDecimal("267694723232435121868"); b2 = new BigDecimal("72111184561789104423"); // Displaying their respective Long Values System.out.println("The Long Value of " + b1 + " is " + b1.longValue()); System.out.println("The Long Value of " + b2 + " is " + b2.longValue()); } } Output: The Long Value of 267694723232435121868 is -9006437873208152372 The Long Value of 72111184561789104423 is -1675791733049102041 Reference:https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#longValue() Comment More infoAdvertise with us Next Article BigDecimal longValue() Method in Java R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Java Java-Functions java-math Java-BigDecimal Java-math-package +2 More Practice Tags : JavaMisc Similar Reads BigDecimal longValueExact() Method in Java The java.math.BigDecimal.longValueExact() is an in-built function which converts this BigDecimal to a long value as well as checks for lost information. This function throws Arithmetic Exception if there is any fractional part of this BigDecimal or if the result of the conversion is too big to be re 3 min read BigDecimal max() Method in Java The java.math.BigDecimal.max(BigDecimal val) method in Java is used to compare two BigDecimal values and return the maximum of the two. This is opposite to BigDecimal max() method in Java. Syntax: public BigDecimal max(BigDecimal val) Parameters: The function accepts a BigDecimal object val as param 2 min read BigInteger longValue() Method in Java The java.math.BigInteger.longValue() converts this BigInteger to a long value. If the value return by this function is too big to fit into long value, then it will return only the low-order 64 bits. There is chance that this conversion can lose information about the overall magnitude of the BigInteg 2 min read BigDecimal intValue() Method in Java The java.math.BigDecimal.intValue() is an in-built function which converts this BigDecimal to an integer value. This function discards any fractional part of this BigDecimal. If the result of the conversion is too big to be represented as an integer value, the function returns only the lower-order 3 2 min read BigDecimal min() Method in Java The java.math.BigDecimal.min(BigDecimal val) method in Java is used to compare two BigDecimal values and return the minimum of the two. Syntax: public BigDecimal min(BigDecimal val) Parameters: The function accepts a BigDecimal object val as parameter whose value is compared with that of this BigDec 2 min read Like