Java Fraction Format format(double input, String format)

Here you can find the source of format(double input, String format)

Description

Formats a number in a specified pattern.

License

Open Source License

Parameter

Parameter Description
input The number to format.
format The formatting pattern, e.g. "0.00" (Number with 2 decimal digits).

Return

The formatted number.

Declaration

public static String format(double input, String format) 

Method Source Code


//package com.java2s;
/*//  www  .  j a v a2 s . c  om
 * Copyright (c) 2014 mgamelabs
 * To see our full license terms, please visit https://github.com/mgamelabs/mengine/blob/master/LICENSE.md
 * All rights reserved.
 */

import java.text.DecimalFormat;

public class Main {
    /**
     * Formats a number in a specified pattern.
     *
     * @param input  The number to format.
     * @param format The formatting pattern, e.g. "0.00" (Number with 2 decimal digits).
     * @return The formatted number.
     */
    public static String format(double input, String format) {
        DecimalFormat decimalFormat = new DecimalFormat(format);
        return decimalFormat.format(input);
    }
}

Related

  1. format(double d)
  2. format(double d, DecimalFormat unitFormatter)
  3. format(Double d, int digit)
  4. format(double d, java.text.NumberFormat format)
  5. format(double degrees)
  6. format(double n)
  7. format(double no, String formatter)
  8. format(Double num)
  9. format(Double num)