Print double number System.out.printf in Java
java
Solution
System.out.printf("%.0f",x);
- The .0 specifies the precision. Number is rounded off according to the precision specified here. (e.g. if you want 2 decimal places you would specify 0.2)
- The f specifies it's a floating point - including doubles (d is for decimal integer)
Problem
I have a double number and i want to print only the integral part of this number. I was trying to print it using `System.out.printf` but i i got an `IllegalFormatConversionException`. I tried something like: ``` A() { double x; //calculate double System.out.println("%d",x); } ``` I know that i can simply print it using `System.out.print` but that will print the decimal part too. How can i do this using `printf`?