Java Decimal Format truncate(double d)

Here you can find the source of truncate(double d)

Description

Truncates a double to two places, and makes it a string.

License

Open Source License

Declaration

public static String truncate(double d) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {
    /** A {@link DecimalFormat} that truncates a decimal to two places. */
    public static final DecimalFormat decFormat = new DecimalFormat("#.##");

    /** Truncates a double to two places, and makes it a string. */
    public static String truncate(double d) {
        return decFormat.format(d);
    }//from   ww w . j ava2 s . c  om
}

Related

  1. toStringNoDigits(double[] v)
  2. toStringScientific(double x)
  3. trim(int degree, double d)
  4. trim(int level, double value)
  5. trim2Decimals(Double value)