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.
public long longValue()
Parameters: This function accepts no parameters.
Return Value: This function returns the long value of this BigDecimal.
Input : 1987812456121.176 Output : 1987812456121 Input : "721111" Output : 721111
Below programs illustrate the use of java.math.BigDecimal.longValue() method:
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.
The Long Value of 267694723232435121868 is -9006437873208152372 The Long Value of 72111184561789104423 is -1675791733049102041
- Short longValue() method in Java with Example
- Long longValue() Method in Java
- BigInteger longValue() Method in Java
- LongAccumulator longValue() method in Java with Examples
- DoubleAdder longValue() method in Java with Examples
- LongAdder longValue() method in Java with Examples
- Number.longValue() method in java with examples
- AtomicInteger longValue() method in Java with examples
- AtomicLong longValue() method in Java with examples
- Byte longValue() method in Java with examples
- DoubleAccumulator longValue() method in Java with Examples
- BigDecimal ulp() Method in Java
- BigDecimal abs() Method in Java
- BigDecimal plus() method in Java
- BigDecimal max() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.