Obtain the integer and fractional parts in Java
Description
The following code shows how to obtain the integer and fractional parts.
Example
// w w w .j a v a 2 s . com
public class Main {
public static void main(String[] args) {
double num;
long iPart;
double fPart;
// Get user input
num = 2.3d;
iPart = (long) num;
fPart = num - iPart;
System.out.println("Integer part = " + iPart);
System.out.println("Fractional part = " + fPart);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »