List of usage examples for java.math BigDecimal doubleValue
@Override public double doubleValue()
From source file:Main.java
/** * Round double value with low error// w w w .j av a2s.co m * * @param value Value * @param places decimal * @return double */ static double round(double value, int places) { // check if places below 0 places = Math.max(0, places); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); }
From source file:Main.java
/** * Rounds a double via passed in amount and places * @param value/*from w w w .j a va2 s. c om*/ * @param places * @return */ public static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); }
From source file:Main.java
public static double round(double value, int scale, int roundingMode) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(scale, roundingMode); double d = bd.doubleValue(); bd = null;/*from w w w. j ava2 s. c o m*/ return d; }
From source file:Main.java
/** * Rounds a double up via passed in amount and places * @param value//from ww w . j a v a 2s.c o m * @param places * @return */ public static double roundUp(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.CEILING); return bd.doubleValue(); }
From source file:Main.java
public static Object round(Object value, int places) { // if (places < 0) throw new IllegalArgumentException(); if (places < 0 || !(value instanceof Double)) { return value; }/*from www .j a v a 2 s.co m*/ BigDecimal bd = new BigDecimal((Double) value); bd = bd.setScale(places, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); }
From source file:Main.java
public static double round(double d, int decimalPlace) { // see the Javadoc about why we use a String in the constructor // http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#BigDecimal(double) BigDecimal bd = new BigDecimal(Double.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); }
From source file:Main.java
@SuppressWarnings("SameParameterValue") private static double round(double value, int places) { if (places < 0) { throw new IllegalArgumentException(); }/*from w ww .j ava2 s . co m*/ BigDecimal bd = new BigDecimal(value); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); }
From source file:com.algoTrader.util.RoundUtil.java
public static BigDecimal roundToNextN(BigDecimal value, double n) { return RoundUtil.getBigDecimal(roundToNextN(value.doubleValue(), n), getDigits(n)); }
From source file:Main.java
public static double transformTwoDecimalDoubleNumber(double number) { BigDecimal bigD = new BigDecimal(number); bigD = bigD.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return bigD.doubleValue(); }
From source file:ch.algotrader.util.RoundUtil.java
public static BigDecimal roundToNextN(BigDecimal value, BigDecimal n) { return RoundUtil.getBigDecimal(roundToNextN(value.doubleValue(), n.doubleValue()), getDigits(n)); }