I am looking to print a double to a variable precision, but without rounding. For example:
Scanner input = new Scanner(System.in);
double num;
System.out.println("Enter a double:");
num = input.nextDouble();
int precision;
System.out.println("Enter precision:");
precision = input.nextInt();
Now I want to print num to the decimal place of precision. Is there a simple way to print this?
EDIT: I have not seen another question answered as to how to use a variable value. The DecimalFormat option rounds the number, which I do not want. Ideally, I am looking for a way to use a variable in:
"%.nf"
rather than
"%.3f"