Java Decimal Round round(double number)

Here you can find the source of round(double number)

Description

Rounds the given number to two decimals.

License

Open Source License

Parameter

Parameter Description
number the number to round

Return

the rounded number

Declaration

private static String round(double number) 

Method Source Code

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

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class Main {
    /**/* w  ww  . ja  va2 s.  co  m*/
     * Rounds the given number to two decimals.
     *
     * @param number the number to round
     * @return the rounded number
     */
    private static String round(double number) {
        DecimalFormat df = new DecimalFormat("#.##");
        df.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.US));
        df.setRoundingMode(RoundingMode.HALF_UP);
        return df.format(number);
    }
}

Related

  1. getRoundedValue(double doubleValue)
  2. getRoundedValue(double value)
  3. round(double d, int n)
  4. round(double d, int p)
  5. round(double dValue)
  6. round(double unrounded, int precision)
  7. round(final double value)
  8. roundAlloc(Double alloc)
  9. roundAndTruncate(double rawValue, int precision)