Java Decimal Round roundTwoDecimals(double d)

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

Description

This method rounds up a decimal number up to N decimals.

License

Open Source License

Parameter

Parameter Description
d The decimal number.

Return

The rounded number.

Declaration

public static final Double roundTwoDecimals(double d) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {
    /**/*from  www  .  j a va2  s.c om*/
     * This method rounds up a decimal number up to N decimals. i.e.. 4,5687 ->
     * 4,56
     *
     * @param d The decimal number.
     *
     * @return The rounded number.
     */
    public static final Double roundTwoDecimals(double d) {
        DecimalFormat twoDForm = new DecimalFormat("#.##");

        return Double.valueOf(twoDForm.format(d));
    }
}

Related

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