Reputation: 357
I know to convert a double value to string , I can do like this :
String value = String.format("%f", 10.0000);
Also I can control the number of digits after decimal using this :
String value = String.format("%.3f", 10.000000);
But my problem is that, I am receiving number of digits after decimal point through a variable. How can I use String.format to print the number of digits after decimal provided by the user.
Regards, Anuj
Upvotes: 1
Views: 186
Reputation: 851
String value = String.format("%."+x+"f", 10.000000);
where x is number of digits.
Upvotes: 5