Question: I need to print a Double as a String but I don't know how many decimal places there will be and I have to be prepared for as many as possible. Right, now I'm using this ugly solution:

```
Double dubs = 0.000157;

NumberFormat formatter = new DecimalFormat(
    "##.########################################################################################");
System.out.println(formatter.format(dubs));

```

Answer: 
You can do this with no conversion:

```
public class codesnippets {

 public static void main(String[] args)
 {
     Double dubs = 0.000157;
     System.out.printf("%f", dubs);
 }

}

```

You can also use

```
Double dubs = 0.000157;
String dubs_format = String.format("%f", dubs);
System.out.println(dubs);

```

EDIT: Apparently there is a precision loss when using "%f" as a format string. If this is the case for you, use "%.10f"
This seemed to work based on Steampunkery's idea. The catch was that I needed an actual String which I realize I wasn't clear on.

```
String dubString= String.format("%f", dubs); 
System.out.println(dubString);

```