Examples of MathContext


Examples of java.math.MathContext

     
      if (result == 0) {
        return BigDecimal.valueOf(180);
      }
     
      return BigDecimal.valueOf(Math.toDegrees(result)).round(new MathContext(ROUNDING_PRECISION, ROUNDING_MODE));
    }
    throw new AlgorithmException("Cannot compute angle of edges which doesn't have a common point");
  }
View Full Code Here

Examples of java.math.MathContext

          .add(linearParameters.getB())
          .subtract(oppositeSideNode.getPointY())
          .compareTo(BigDecimal.ZERO);
    }
   
    BigDecimal Cos60 = BigDecimal.valueOf(Math.cos(Math.toRadians(60))).round(new MathContext(ROUNDING_PRECISION, ROUNDING_MODE));
    BigDecimal Sin60 = BigDecimal.valueOf(Math.sin(Math.toRadians(60))).round(new MathContext(ROUNDING_PRECISION, ROUNDING_MODE));
   
    // try to turn point clockwise to find coordinates of the third triangle's point
    BigDecimal turnedX = Cos60.multiply(linearParameters.getDx()).subtract(Sin60.multiply(linearParameters.getDy())).add(edge.getStart().getPointX());
    BigDecimal turnedY = Sin60.multiply(linearParameters.getDx()).add(Cos60.multiply(linearParameters.getDy())).add(edge.getStart().getPointY());
   
View Full Code Here

Examples of java.math.MathContext

    } else {
      // x = (b2 - b1) / ( k1 - k2 )
      centerX = secondEdgeParameters.getB()
          .subtract(firstEdgeParameters.getB())
          .divide(firstEdgeParameters.getK()
          .subtract(secondEdgeParameters.getK()), new MathContext(DIVISION_PRECISION, ROUNDING_MODE));
     
      // y = k * x - b
      centerY = firstEdgeParameters.getK()
          .multiply(centerX)
          .add(firstEdgeParameters.getB());
View Full Code Here

Examples of java.math.MathContext

      return null;
    }
   
    // find result points
    BigDecimal x1 = b.negate()
        .subtract(BigDecimal.valueOf(Math.sqrt(D.doubleValue())), new MathContext(DIVISION_PRECISION, ROUNDING_MODE))
        .divide(a.multiply(BigDecimal.valueOf(2)), DIVISION_PRECISION, ROUNDING_MODE);
   
    BigDecimal x2 = b.negate()
        .add(BigDecimal.valueOf(Math.sqrt(D.doubleValue())))
        .divide(a.multiply(BigDecimal.valueOf(2)), DIVISION_PRECISION, ROUNDING_MODE);
View Full Code Here

Examples of java.math.MathContext

  public static BigDecimal getGraphLength(Graph<WeightedEdge> graph) {
    BigDecimal result = BigDecimal.ZERO;
    result.setScale(ROUNDING_PRECISION);
   
    for (WeightedEdge edge : graph.getEdgeList()) {
      result = result.add(edge.getWeight(), new MathContext(ROUNDING_PRECISION, ROUNDING_MODE));
    }
    return result;
  }
View Full Code Here

Examples of java.math.MathContext

                    BigDecimal minutes = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(2, 4)));
                    BigDecimal sixty = new BigDecimal(60.00);
                    String direction = temp.toString().substring(4);
                    //Decimal Degrees = Degrees + minutes/60
                    BigDecimal convertedCoordinates = degrees.add(minutes.divide(sixty, new MathContext(5)));
                    //negate coordinate if it is -> South
                    if (direction.toLowerCase().equals("s")) {
                        convertedCoordinates.negate();
                    }
                    mainTable.setValueAt(convertedCoordinates, i, selectedColIndex);
                } else if (temp != null && temp.toString().length() == 7) {//latitude with seconds

                    //Uses BigDecimal in order to enabe control of precision after the .
                    //and get precise coordinate value

                    //Get subSting of a number and convert it to BigDecimal
                    BigDecimal degrees = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(0, 2)));

                    BigDecimal minutes = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(2, 4)));
                    minutes = minutes.divide(new BigDecimal(60), new MathContext(5));

                    BigDecimal seconds = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(4, 6)));
                    seconds = seconds.divide(new BigDecimal(3600), new MathContext(5));

                    String direction = temp.toString().substring(6);
                    //Decimal Degrees = Degrees + minutes/60
                    BigDecimal convertedCoordinates = degrees.add(minutes.add(seconds), new MathContext(5));

                    //negate coordinate if it is -> South
                    if (direction.toLowerCase().equals("s")) {
                        convertedCoordinates.negate();
                    }
                    mainTable.setValueAt(convertedCoordinates, i, selectedColIndex);
                } else {
                    statusBar.setMessage("Data in selected column does not seem to be of appropriate type.");
                    return;
                }
                columnStatus.put(selectedColIndex, "Latitude");
            }
            statusBar.setMessage("Column data type set to - Latitude. Values converted to KML format.");
        }

        //if Longitude
        if (coordinateType == 1 && jRadioButtonCoordinates.isSelected()) {
            int rowCount = mainTable.getRowCount();
            for (int i = 0; i < rowCount; i++) {
                //get row from the selected column
                Object temp = mainTable.getValueAt(i, selectedColIndex);
                if (temp != null && temp.toString().length() == 6) { //Longitude without seconds
                    //Uses BigDecimal in order to enabe control of precision after the .
                    //and get precise coordinate value

                    //Get subSting of a number and convert it to BigDecimal
                    //degrees
                    BigDecimal degrees = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(0, 3)));
                    //minutes/60
                    BigDecimal minutes = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(3, 5)));
                    minutes = minutes.divide(new BigDecimal(60), new MathContext(5));

                    //direction
                    String direction = temp.toString().substring(5);

                    //Decimal Degrees = Degrees + minutes/60
                    BigDecimal convertedCoordinates = degrees.add(minutes, new MathContext(5));

                    //negate coordinate if it is -> West
                    if (direction.toLowerCase().equals("w")) {
                        convertedCoordinates = convertedCoordinates.negate();
                    }
                    mainTable.setValueAt(convertedCoordinates, i, selectedColIndex);
                } else if (temp != null && temp.toString().length() == 8) {//Longitude with seconds
                    //Uses BigDecimal in order to enabe control of precision after the .
                    //and get precise coordinate value

                    //Get subSting of a number and convert it to BigDecimal
                    //degrees
                    BigDecimal degrees = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(0, 3)));
                    //minutes/60
                    BigDecimal minutes = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(3, 5)));
                    minutes = minutes.divide(new BigDecimal(60), new MathContext(5));
                    //seconds/3600
                    BigDecimal seconds = new BigDecimal(Double.parseDouble(
                            temp.toString().substring(4, 7)));
                    seconds = seconds.divide(new BigDecimal(3600), new MathContext(5));
                    //direction
                    String direction = temp.toString().substring(7);

                    //Decimal Degrees = Degrees + minutes/60 + seconds/3600
                    BigDecimal convertedCoordinates = degrees.add(minutes.add(seconds), new MathContext(5));

                    //negate coordinate if it is -> West
                    if (direction.toLowerCase().equals("w")) {
                        convertedCoordinates = convertedCoordinates.negate();
                    }
View Full Code Here

Examples of java.math.MathContext

                // go through each product quantity and divide it by the occurances to get the average
                for (Map.Entry<String, BigDecimal> entry : productQuantities.entrySet()) {
                    String prodId = entry.getKey();
                    BigDecimal quantity = entry.getValue();
                    Integer occs = productOccurances.get(prodId);
                    BigDecimal nqint = quantity.divide(new BigDecimal(occs), new MathContext(10));

                    if (nqint.compareTo(BigDecimal.ONE) < 0) nqint = BigDecimal.ONE;
                    productQuantities.put(prodId, nqint);
                }
               
View Full Code Here

Examples of java.math.MathContext

  public BigDecimal getBigDecimal(String columnName) throws SQLException {
    return getBigDecimal(findColumn(columnName));
  }

  public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
    MathContext mc = new MathContext(scale);
    return getBigDecimal(columnIndex).round(mc);
  }
View Full Code Here

Examples of java.math.MathContext

        try {
            // check if the invoice is posted and get the conversion from there
            List<GenericValue> acctgTransEntries = invoice.getRelated("AcctgTrans");
            if (UtilValidate.isNotEmpty(acctgTransEntries)) {
                GenericValue acctgTransEntry = (acctgTransEntries.get(0)).getRelated("AcctgTransEntry").get(0);
                conversionRate = acctgTransEntry.getBigDecimal("amount").divide(acctgTransEntry.getBigDecimal("origAmount"), new MathContext(100)).setScale(decimals,rounding);
            }
            // check if a payment is applied and use the currency conversion from there
            if (UtilValidate.isEmpty(conversionRate)) {
                List<GenericValue> paymentAppls = invoice.getRelated("PaymentApplication");
                for (GenericValue paymentAppl : paymentAppls) {
                    GenericValue payment = paymentAppl.getRelatedOne("Payment");
                    if (UtilValidate.isNotEmpty(payment.getBigDecimal("actualCurrencyAmount"))) {
                        if (UtilValidate.isEmpty(conversionRate)) {
                            conversionRate = payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100)).setScale(decimals,rounding);
                        } else {
                            conversionRate = conversionRate.add(payment.getBigDecimal("amount").divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100))).divide(new BigDecimal("2"),new MathContext(100)).setScale(decimals,rounding);
                        }
                    }
                }
            }
            // use the dated conversion entity
            if (UtilValidate.isEmpty(conversionRate)) {
                List<GenericValue> rates = EntityUtil.filterByDate(delegator.findByAnd("UomConversionDated", UtilMisc.toMap("uomIdTo", invoice.getString("currencyUomId"), "uomId", otherCurrencyUomId)), invoice.getTimestamp("invoiceDate"));
                if (UtilValidate.isNotEmpty(rates)) {
                    conversionRate = (BigDecimal.ONE).divide((rates.get(0)).getBigDecimal("conversionFactor"), new MathContext(100)).setScale(decimals,rounding);
                } else {
                    Debug.logError("Could not find conversionrate for invoice: " + invoice.getString("invoiceId"), module);
                    return new BigDecimal("1");
                }
            }
View Full Code Here

Examples of java.math.MathContext

            if (paymentApplication.get("paymentId") != null) {
                GenericValue payment = paymentApplication.getRelatedOne("Payment");
                if (paymentApplication.get("invoiceId") != null && payment.get("actualCurrencyAmount") != null && payment.get("actualCurrencyUomId") != null) {
                    GenericValue invoice = paymentApplication.getRelatedOne("Invoice");
                    if (payment.getString("actualCurrencyUomId").equals(invoice.getString("currencyUomId"))) {
                           appliedAmount = appliedAmount.multiply(payment.getBigDecimal("amount")).divide(payment.getBigDecimal("actualCurrencyAmount"),new MathContext(100));
                    }
                }
            }
        } catch (GenericEntityException e) {
            Debug.logError(e, "Problem getting Payment", module);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.