Reputation: 11
How to printf decimal point by user? For example:
float a = 122.32445;
int decimal = 2;
And I want to print 122.32 I know that exist:
System.out.printf("%.2f", a);
But how to implement that decimal point there? I came up with something like this:
System.out.printf("%.%df, decimal, a);
But it of course it doesn't work. Thanks for any help.
Upvotes: 0
Views: 50
Reputation: 1
I would assume that
DecimalFormat decimalFormat = new DecimalFormat("##,##0.00");
does the trick.
Upvotes: 0