Java Decimal Round roundTwoDecimals(double d)

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

Description

round Two Decimals

License

Open Source License

Declaration

public static double roundTwoDecimals(double d) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {
    public static double roundTwoDecimals(double d) {

        try {//from   w w  w  .  j  ava  2  s. c om
            DecimalFormat twoDForm = new DecimalFormat("#.##");
            return Double.valueOf(twoDForm.format(d));
        } catch (NumberFormatException e) {
            return d;
        }
    }
}

Related

  1. roundNumDecimals(double d, int num)
  2. roundOffToTwoDecimal(double value)
  3. roundThreeDecimals(double d)
  4. roundTwoDecimals(Double d)
  5. roundTwoDecimals(double d)
  6. roundTwoDecimals(double d)
  7. to_decimal(double v)
  8. toLimitDecimalFloatStr(double number, int newScale)
  9. toNumber(Double value, Double defaultValue)