Java - Write code to Convert a float to a string with format

Requirements

Write code to Convert a float to a string with format

Demo

//package com.book2s;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] argv) {
        float value = 42.45678f;
        String format = "#.00";
        System.out.println(floatToString(value, format));
    }/*www . j  a v a 2  s  .com*/

    /**
     * Converts a float to a string.
     * 
     * @param value
     * @param format
     *          The format, e.g. #.00
     * @return
     */
    public static String floatToString(float value, String format) {
        return doubleToString(value, format);
    }

    /**
     * Converts a double to a string.
     * 
     * @param value
     * @param format
     *          The format, e.g. #.00
     * @return
     */
    public static String doubleToString(double value, String format) {
        return new DecimalFormat(format).format(value);
    }
}