Computer Science, asked by emmabowen2005, 11 months ago

Which line of code outputs the decimal portion of a float stored in the variable x?

Answers

Answered by nidaeamann
1

Explanation:

There are no code lines as per question statement. So lets us write the code for outputting the decimal points of a floating number.

The below code is written in python language

Code:

System.out.println("With rounding upto 2 decimals");

float n = 44.12f;

System.out.printf("n %% 1= %.2f%n", n % 1);

System.out.printf("n - Math.floor(n) = %.2f%n", n - Math.floor(n));

System.out.printf("n - (int)n= %.2f%n", n - (int)n);

Code simulation :

With rounding upto 2 decimals

n % 1= 0.12

n - Math.floor(n) = 0.12

n - (int)n= 0.12

Similar questions