/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		System.out.println(format(0.4999d, 1));
		System.out.println(format(0.0299d, 2));
		System.out.println(format(0.34943d, 3));
		System.out.println(format(0.98499d, 3));
		System.out.println(format(0.66666666d, 5));
		
		System.out.println("---------");
		
		// briancherron - Standard method
		
		NumberFormat nf = NumberFormat.getInstance();
		nf.setMaximumIntegerDigits(0);
		
		System.out.println(nf.format(0.4999d));
		System.out.println(nf.format(0.0299d));
		System.out.println(nf.format(0.34943d));
		System.out.println(nf.format(0.98499d));
		nf.setMaximumFractionDigits(5);
		System.out.println(nf.format(0.66666666d));
		
	}
	
	public static String format(double value, int decimalPlaces) {
		if (value >= 1 || value < 0) {
			throw new IllegalArgumentException("Value must be between 0 and 1");
		}
		String tmp = String.format("%." + decimalPlaces + "f", value);
		return tmp.substring(1);
	}
	
	
}