Java Decimal Round round(double unrounded, int precision)

Here you can find the source of round(double unrounded, int precision)

Description

round

License

Apache License

Declaration

public static String round(double unrounded, int precision) 

Method Source Code

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

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Main {
    public static String round(double unrounded, int precision) {
        DecimalFormat df = new DecimalFormat("####0.##########");
        BigDecimal bd = new BigDecimal(unrounded);
        BigDecimal rounded = bd.setScale(precision,
                BigDecimal.ROUND_HALF_UP);
        return df.format(rounded.doubleValue());
    }/*from  w  w w .j  a va2s.c o  m*/
}

Related

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