Java Number Format format(int decs, double number)

Here you can find the source of format(int decs, double number)

Description

Formats a number to a given amount of decimal places.

License

Open Source License

Parameter

Parameter Description
decs Decimal numbers to display
number The number to format

Return

Formatted number String

Declaration

public static String format(int decs, double number) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w  ww  .ja  v a  2 s.  c o m
     * Formats a number to a given amount of decimal places.
     * 
     * @param decs Decimal numbers to display
     * @param number The number to format
     * @return Formatted number String
     */
    public static String format(int decs, double number) {
        return String.format("%." + decs + "f", number);
    }
}

Related

  1. format(int number, int length)
  2. format(Number number)
  3. format(String number)
  4. format(String number)