0

How can I display only 2 decimal points with float variable? I'm also using Scanner

float num;
System.out.println("Enter any number");
num = user_input.nextFloat();
System.out.println("Square of " + num + " is: "+Math.pow(num, 2));
  • Use `%2.2f`, number before decimal point is for the minimum number of characters used to display integral part, the number after is for the maximum number of digits included after decimal point. – 11thdimension Aug 15 '16 at 03:47
  • are there some other ways? I mean I'm using square to display the float variable with 2 decimal places – cookieWarrior Aug 15 '16 at 04:02

0 Answers0