Displays the integer and fractional parts of a floating-point number separately, and the Java display
For example:
Please enter any decimal: 16.69
Integer part: 16
Fractional part: 0.69
The code implementation is as follows:
* * Please enter any decimal: 16.69
integer part:
decimal part: 0.69
* * */Public
class Dividefloatnumber {public
static void Main (string[] args) {
float inputfloat=0f;
String floatstring;
int pointindex = 0;//decimal Position
//Enter a floating-point number
Scanner Scanner = new Scanner (system.in);
System.out.println ("Please enter a floating-point number:");
Inputfloat = Scanner.nextfloat ();
The integer portion of the output floating-point number
System.out.println (inputfloat+ "" + (int) inputfloat);
Output floating-point number of decimal parts, note the positive sign
floatstring = inputfloat+ "";
PointIndex = Floatstring.indexof ('. ');
Integral part of System.out.println (inputfloat+ ":
+float.parsefloat (floatstring.charat (0) = = '?" -":" ")
+" 0. " +floatstring.substring ((pointindex+1), Floatstring.length ())));
}