I want to use a non hard coded value after decimal point in printf statement . Below is my code . Instead of 4 I want to set to x.
int x = sc.nextInt();
double d=103993d/33102d;
System.out.printf("%.4f", d);
Declare a variable and concatenate with the formatting string as below
double d=103993d/33102d;
int x=9;
System.out.printf("%."+x+"f", d);
OUTPUT:-
3.141592653
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With