List of usage examples for java.math BigDecimal doubleValue
@Override public double doubleValue()
From source file:edu.ku.brc.specify.config.LatLonConverter.java
/** * Converts BigDecimal to Degrees and Decimal Minutes. * @param bd the DigDecimal to be converted. * @return a 2 piece string// ww w .ja v a2 s.c o m */ public static String convertToDDMMMM(final BigDecimal bd, final DEGREES_FORMAT degreesFMT, final DIRECTION direction, final int decimalLen, final boolean alwaysIncludeDir) { if (bd.doubleValue() == 0.0) { return "0.0"; } if (useDB) { BigDecimal remainder = bd.remainder(one); BigDecimal num = bd.subtract(remainder); BigDecimal minutes = remainder.multiply(sixty).abs(); //System.out.println("["+decFormatter2.format(num)+"]["+minutes+"]"); return decFormatter2.format(num) + " " + decFormatter2.format(minutes); } //else boolean addMinSecsSyms = degreesFMT != DEGREES_FORMAT.None; double num = Math.abs(bd.doubleValue()); int whole = (int) Math.floor(num); double remainder = num - whole; double minutes = remainder * 60.0; //System.out.println("["+whole+"]["+String.format("%10.10f", new Object[] {minutes})+"]"); StringBuilder sb = new StringBuilder(); sb.append(whole); if (degreesFMT == DEGREES_FORMAT.Symbol) { sb.append("\u00B0"); } sb.append(' '); // round to four decimal places of precision //minutes = Math.round(minutes*10000) / 10000; sb.append(String.format("%" + 2 + "." + decimalLen + "f", minutes)); if (addMinSecsSyms) sb.append("'"); if (degreesFMT == DEGREES_FORMAT.String || alwaysIncludeDir) { int inx = bd.doubleValue() < 0.0 ? 1 : 0; if (direction != DIRECTION.None) { sb.append(' '); sb.append(direction == DIRECTION.NorthSouth ? northSouth[inx] : eastWest[inx]); } } //return whole + (degreesFMT == DEGREES_FORMAT.Symbol ? "\u00B0" : "") + " " + StringUtils.strip(String.format("%10.10f", new Object[] {minutes}), "0"); return sb.toString(); }
From source file:edu.ku.brc.specify.config.LatLonConverter.java
/** * Converts BigDecimal to Degrees, Minutes and Decimal Seconds. * @param bd the DigDecimal to be converted. * @return a 3 piece string//from ww w .ja v a 2 s. c o m */ public static String convertToDDMMSS(final BigDecimal bd, final DEGREES_FORMAT degreesFMT, final DIRECTION direction, final int decimalLen, final boolean alwaysIncludeDir) { if (bd.doubleValue() == 0.0) { return "0." + zeroes.substring(0, decimalLen); } if (useDB) { BigDecimal remainder = bd.remainder(one); BigDecimal num = bd.subtract(remainder); BigDecimal minutes = new BigDecimal(remainder.multiply(sixty).abs().intValue()); BigDecimal secondsFraction = remainder.abs().multiply(sixty).subtract(minutes); BigDecimal seconds = secondsFraction.multiply(sixty); //System.out.println("["+decFormatter2.format(num)+"]["+minutes+"]["+seconds+"]"); return decFormatter2.format(num) + " " + decFormatter2.format(minutes) + " " + decFormatter.format(seconds); } //else double num = Math.abs(bd.doubleValue()); int whole = (int) Math.floor(num); double remainder = num - whole; double minutes = remainder * 60.0; int minutesWhole = (int) Math.floor(minutes); double secondsFraction = minutes - minutesWhole; double seconds = secondsFraction * 60.0; boolean addMinSecsSyms = degreesFMT != DEGREES_FORMAT.None; if (minutesWhole == 60) { whole += 1; minutesWhole = 0; } // round to 2 decimal places precision seconds = Math.round(seconds * 1000) / 1000.0; int secondsWhole = (int) Math.floor(seconds); if (secondsWhole == 60) { minutesWhole += 1; seconds = 0.0; } StringBuilder sb = new StringBuilder(); sb.append(whole); if (degreesFMT == DEGREES_FORMAT.Symbol) { sb.append(DEGREES_SYMBOL); } sb.append(' '); sb.append(minutesWhole); if (addMinSecsSyms) sb.append("'"); sb.append(' '); sb.append(String.format("%2." + decimalLen + "f", seconds)); if (addMinSecsSyms) sb.append("\""); if (degreesFMT == DEGREES_FORMAT.String || alwaysIncludeDir) { int inx = bd.doubleValue() < 0.0 ? 1 : 0; if (direction != DIRECTION.None) { sb.append(' '); sb.append(direction == DIRECTION.NorthSouth ? northSouth[inx] : eastWest[inx]); } } //System.err.println("["+sb.toString()+"]"); //return whole + (DEGREES_FORMAT.None ? "\u00B0" : "") + " " + minutesWhole + " " + StringUtils.strip(String.format("%12.10f", new Object[] {seconds}), "0"); return sb.toString(); }
From source file:com.idylwood.utils.MathUtils.java
final public static double meanArbPrec(final double data[]) { BigDecimal mean = new BigDecimal(0); for (double x : data) mean = mean.add(new BigDecimal(x), MathContext.UNLIMITED); mean = mean.divide(new BigDecimal(data.length), MathContext.UNLIMITED); return mean.doubleValue(); }
From source file:com.mycompany.thymeleafspringapp.dao.DealsDaoImpl.java
@Override public void closeDeal(Deals deal, BigDecimal closePrice, Date closeDate) { deal.setDateClose(closeDate);//from w w w . j a v a 2 s. c o m deal.setPriceClose(closePrice.doubleValue()); persistDeal(deal); }
From source file:com.idylwood.utils.MathUtils.java
static final double linearCombinationArbitraryPrecision(final double[] x, final double[] y) { final int len = Math.min(x.length, y.length); //final double [][] ret = new double[len][2]; BigDecimal ret = new BigDecimal(0); for (int i = len; 0 != i--;) { BigDecimal product = new BigDecimal(x[i]).multiply(new BigDecimal(y[i]), MathContext.UNLIMITED); ret = ret.add(product, MathContext.UNLIMITED); }// w w w. j a v a2 s .c o m return ret.doubleValue(); }
From source file:it.polimi.diceH2020.SPACE4Cloud.shared.solution.SolutionPerJob.java
public void setCost() { double cost = deltaBar * numOnDemandVM + rhoBar * numReservedVM + sigmaBar * numSpotVM + job.getPenalty() * (job.getHup() - numberUsers); BigDecimal c = BigDecimal.valueOf(cost).setScale(4, RoundingMode.HALF_EVEN); this.cost = c.doubleValue(); }
From source file:data.dao.CarDao.java
public List<Car> getCarLesserPrice(BigDecimal price) { Criteria cr = currentSession().createCriteria(getSupportedClass()); cr.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); cr.add(Restrictions.le("cmPrice", price.doubleValue())); cr.add(Restrictions.gt("cmPrice", Double.valueOf("0.0"))); return cr.list(); }
From source file:feedme.model.Order.java
public 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:de.andreasschoknecht.LS3.LSSMCalculator.java
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:tibano.service.ParkService.java
@RequestMapping(path = "/getPaymentInfo") PaymentInfo getPaymentInfo(@RequestParam(name = "areaId") Long areaId, @RequestParam(name = "licensePlate") String licensePlate) { ParkingTransaction pt = ptRepository.findOpenTransactionByAreaAndLicensePlate(areaId, licensePlate); if (pt != null) { Duration duration = Duration.between(pt.getStart(), LocalDateTime.now()); Double amount = duration.getSeconds() * SEC_TARIF; BigDecimal bd = new BigDecimal(amount); bd = bd.setScale(2, RoundingMode.HALF_UP); Integer loyaltyPoints = 5 + Integer.valueOf(Double.valueOf(bd.doubleValue()).intValue()); return new PaymentInfo(pt.getEnd(), amount, duration, loyaltyPoints); }//from www . j a va2s .c o m return new PaymentInfo(null, Double.valueOf(0), Duration.ZERO, Integer.valueOf(0)); }