Java Decimal Round roundTwoDecimals(Double d)

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

Description

Round up to two decimals

License

Apache License

Parameter

Parameter Description
d a parameter

Declaration

public static Double roundTwoDecimals(Double d) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {
    /**// w w  w  .j  a va 2s.c o  m
     * Round up to two decimals
     *
     * @param d
     * @return
     */
    public static Double roundTwoDecimals(Double d) {
        DecimalFormat twoDForm = new DecimalFormat("###.##");
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setDecimalSeparator('.');
        twoDForm.setDecimalFormatSymbols(dfs);
        return Double.valueOf(twoDForm.format(d));
    }
}

Related

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