Java Number.longValue() Method Last Updated : 15 May, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Number.longValue() is an inbuilt method in Java of java.lang package. This method is used to convert any numeric value into a long type. This may involve rounding or truncation.What is longValue()?The longValue() method returns the value of a number after converting it to the long data type. Sometimes this involves rounding or truncating decimal points, when the original value is a floating-point number like float or double.Syntax of Number.longValue() Methodpublic abstract long longValue()Parameters: This method does not accept any parameters. Return value: This method returns the numeric value represented by this object after conversion to type long.Examples of Java Number.longValue() MethodExample 1: In this example, we are going to convert a Float and Double object into a long using the longValue() method. Java // Java program to demonstrate // the use of Number.longValue() method import java.lang.Number; public class Geeks { public static void main(String[] args) { // Create a Float object Float f = new Float(127483456f); // Convert Float to long using longValue() long longFromFloat = f.longValue(); System.out.println("Float to long: " + longFromFloat); // Create a Double object Double d = new Double(78549876); // Convert Double to long using longValue() long longFromDouble = d.longValue(); System.out.println("Double to long: " + longFromDouble); } } OutputFloat to long: 127483456 Double to long: 78549876 Example 2: In this example, we are converting decimal values to long, and we will observe how the decimal portion is truncated in the output. Java // Java program to demonstrate // truncation using longValue() method import java.lang.Number; public class Geeks { public static void main(String[] args) { // Create a Float with no decimal part Float f = new Float(127f); System.out.println("Float to long: " + f.longValue()); // Create a Double with a decimal part Double d = new Double(76.23); System.out.println("Double to long: " + d.longValue()); } } OutputFloat to long: 127 Double to long: 76 Important Points:This method makes it easy to convert any number like a Float, Double, or Integer into a long. We don’t have to worry about writing extra code to cast or convert manually. Just by calling the method, we get the number in long form.This is very useful when we are working with different number types but want to treat them all the same.When we are working with whole numbers. For example, if you don’t care about the decimal part and just need the whole number like storing prices, counts, or IDs, this method keeps things simple. Comment More infoAdvertise with us Next Article Long longValue() Method in Java T Twinkl Bajaj Follow Improve Article Tags : Java Java-lang package Java-Functions Practice Tags : Java Similar Reads Number.longValue() method in java with examples The Number.longValue() is an inbuilt method in Java of java.lang package. This method is used to convert any numeric value into a long type. This may involve rounding or truncation.What is longValue()?The longValue() method returns the value of a number after converting it to the long data type. Som 2 min read Long longValue() Method in Java The java.lang.Long.longValue() is an inbuilt method of the Long class in Java which returns the value of this Long object as a long after the conversion.Syntax: public long longValue() Parameters: This method does not take any parameters.Return Value: This method will return the numeric value repres 2 min read Long signum() Method in Java The signum function also known as sign function is an odd mathematical function that extracts the sign of a real number. The java.lang.Long.signum() method is used to get the signum function of the specified long value. For a positive value, a negative value and zero, the method returns 1, -1 and 0 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 longValue() Method in Java 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 2 min read Short longValue() method in Java with Example The java.lang.Short.longValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a long. Syntax ShortObject.longValue() Return Value: It return the value of ShortObject as long. Below is the implementation of longValue() method in Java: Exam 2 min read Java Number.longValue() Method min read Like