Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

In this page you can find the example usage for java.lang Double parseDouble.

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

Returns a new double initialized to the value represented by the specified String , as performed by the valueOf method of class Double .

Usage

From source file:com.krawler.common.util.SchedulingUtilities.java

public static double getDurationInDays(String duration) {
    double d = -1;
    boolean f = false;
    if (!StringUtil.isNullOrEmpty(duration)) {
        if (duration.contains("h")) {
            duration = duration.substring(0, duration.indexOf('h'));
            f = true;/*from   w  w  w .  java2  s .  c  o m*/
        } else if (duration.contains("d")) {
            duration = duration.substring(0, duration.indexOf('d'));
        }
        d = Double.parseDouble(duration);
        if (f) {
            d = d / 8;
        }
    }
    return d;
}

From source file:com.glaf.jbpm.util.CustomFieldInstantiator.java

public static Object getValue(Class<?> type, Element propertyElement) {
    Object value = null;/*from   w w w. java2s  . co m*/
    if (type == String.class) {
        value = propertyElement.getText();
    } else if ((type == Integer.class) || (type == int.class)) {
        value = Integer.parseInt(propertyElement.getTextTrim());
    } else if ((type == Long.class) || (type == long.class)) {
        value = Long.parseLong(propertyElement.getTextTrim());
    } else if ((type == Float.class) || (type == float.class)) {
        value = new Float(propertyElement.getTextTrim());
    } else if ((type == Double.class) || (type == double.class)) {
        value = Double.parseDouble(propertyElement.getTextTrim());
    } else if ((type == Boolean.class) || (type == boolean.class)) {
        value = Boolean.valueOf(propertyElement.getTextTrim());
    } else if ((type == Character.class) || (type == char.class)) {
        value = Character.valueOf(propertyElement.getTextTrim().charAt(0));
    } else if ((type == Short.class) || (type == short.class)) {
        value = Short.valueOf(propertyElement.getTextTrim());
    } else if ((type == Byte.class) || (type == byte.class)) {
        value = Byte.valueOf(propertyElement.getTextTrim());
    } else if (type.isAssignableFrom(java.util.Date.class)) {
        value = DateUtils.toDate(propertyElement.getTextTrim());
    } else if (type.isAssignableFrom(List.class)) {
        value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>());
    } else if (type.isAssignableFrom(Set.class)) {
        value = getCollectionValue(propertyElement, new LinkedHashSet<Object>());
    } else if (type.isAssignableFrom(Collection.class)) {
        value = getCollectionValue(propertyElement, new java.util.ArrayList<Object>());
    } else if (type.isAssignableFrom(Map.class)) {
        value = getMapValue(propertyElement, new LinkedHashMap<Object, Object>());
    } else if (type == Element.class) {
        value = propertyElement;
    } else {
        try {
            Constructor<?> constructor = type.getConstructor(new Class[] { String.class });
            if ((propertyElement.isTextOnly()) && (constructor != null)) {
                value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() });
            }
        } catch (Exception ex) {
            logger.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '"
                    + type.getName() + "'");
            throw new RuntimeException(ex);
        }
    }

    return value;
}

From source file:com.ctt.entity.Transaction.java

public Transaction(CSVRecord record) {
    try {// www . j ava 2 s.co m
        System.out.println(record.get(0));
        String[] rr = record.get(0).split(";");

        System.out.println("0" + rr[0]);

        this.type_repayment = rr[0];

        this.type_id = rr[1];
        this.client_id = rr[2];
        this.value_transaction = Double.parseDouble(rr[3]);
        this.value_repayment = Double.parseDouble(rr[4]);
        this.tax = Double.parseDouble(rr[5]);
        this.type_tax = rr[6];
        this.code_bank = rr[7];
        this.card_number = rr[8];
        this.type_card = rr[9];

        this.isCreditCardTransaction = rr[10];

        this.dues = Integer.parseInt(rr[11]);

        if (rr.length >= 13)
            this.observations = rr[12];

    } catch (NumberFormatException ex) {
        Main.appendLog("Error: INIT TRANSACTION " + ex.getMessage());
    }

}

From source file:com.vsthost.rnd.commons.math.ext.linear.IOUtils.java

/**
 * Reads a matrix of double values from the reader provided.
 *
 * @param reader The reader which the values to be read from.
 * @return A matrix//w  w  w.  j av a 2 s  .  co  m
 * @throws IOException As thrown by the CSV parser.
 */
public static RealMatrix readMatrix(Reader reader) throws IOException {
    // Initialize the return value:
    List<double[]> retval = new ArrayList<>();

    // Parse and get the iterarable:
    Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(reader);

    // Iterate over the records and populate return value:
    for (CSVRecord record : records) {
        double[] row = new double[record.size()];
        for (int i = 0; i < record.size(); i++) {
            row[i] = Double.parseDouble(record.get(i));
        }
        retval.add(row);
    }

    // Convert the list to an array:
    double[][] retvalArray = new double[retval.size()][];
    retval.toArray(retvalArray);

    // Done, return the array:
    return MatrixUtils.createRealMatrix(retvalArray);
}

From source file:com.prey.json.actions.Geofencing.java

public void start(Context ctx, List<ActionResult> lista, JSONObject parameters) {

    try {//www.  j  a  v  a  2 s  . c  om

        String origin = parameters.getString("origin");
        String[] centralPoints = origin.split(",");
        String longitude = centralPoints[0];
        String latitude = centralPoints[1];
        String radius = parameters.getString("radius");

        Bundle bundle = new Bundle();
        bundle.putDouble("longitude", Double.parseDouble(longitude));
        bundle.putDouble("latitude", Double.parseDouble(latitude));
        bundle.putFloat("radius", Float.parseFloat(radius));
        bundle.putInt("type", ProxAlertActivity.START);

        Intent popup = new Intent(ctx, ProxAlertActivity.class);
        popup.putExtras(bundle);
        popup.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx.startActivity(popup);

        PreyLogger.i("Finish Geofencing start");

    } catch (JSONException e) {
        PreyLogger.e("Error en json:" + e.getMessage(), e);
        PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx,
                UtilJson.makeMapParam("start", "geofence", "failed", e.getMessage()));
    }

}

From source file:web.Validator.ModificationValidator.java

@Override
public void validate(Object o, Errors errors) {
    CommandModification command = (CommandModification) o;
    SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
    if (command.getDateNaissance() != null) {
        if (!command.getDateNaissance().isEmpty()) {
            try {
                Date parse = myFormatter.parse(command.getDateNaissance());
            } catch (Exception e) {
                errors.rejectValue("dateNaissance", "Erreur forme date", "Date format must be yyyy-mm-dd");
            }//from www .ja  va  2  s .com
        }
    }
    if (command.getTelephone() != null) {
        try {
            Double d = Double.parseDouble(command.getTelephone());
            if (command.getTelephone().length() != 8)
                errors.rejectValue("telephone", "Erreur log tel", "Tel must be 8 digits long");
        } catch (Exception e) {
            errors.rejectValue("telephone", "Erreur format tel",
                    "Tel must contain only numbers AND 8 digits long");
        }
    }
    if (command.getCin() != null) {
        try {
            int i = Integer.parseInt(command.getCin());
            if (command.getCin().length() != 8)
                errors.rejectValue("cin", "Erreur format cin", "CIN must contain 8 digits");
        } catch (Exception e) {
            errors.rejectValue("cin", "Erreur format cin", "CIN must contain only digits");
        }
    }
    if (command.getLogin().isEmpty()) {
        errors.rejectValue("login", "Erreur login", "Must be filled");
    }
    if (command.getPass().isEmpty()) {
        errors.rejectValue("pass", "Erreur login", "Must be filled");
    }
}

From source file:com.swcguild.springmvcwebapp.controller.InterCalcController.java

@RequestMapping(value = "/intercalc", method = RequestMethod.POST)
public String doPost(HttpServletRequest request, Model model) {

    try {//from  w ww. j ava2  s  .  c o m
        originalBalance = Double.parseDouble(request.getParameter("myAnswer"));
        startingBalance = originalBalance;
        intRate = Double.parseDouble(request.getParameter("myRate"));
        numYears = Double.parseDouble(request.getParameter("myYears"));
        numPeriods = Double.parseDouble(request.getParameter("myPeriods"));
        message = "";
        //totalInterest;
        //newBalance;
        //List<Map> annualInterest = new ArrayList<>();
        Map yearMap = new HashMap<>();
        DecimalFormat df = new DecimalFormat("#.00");

        int yearCount = 0;

        do {
            newBalance = originalBalance * (Math.pow(1 + ((intRate * .01) / numPeriods), (numPeriods)));
            yearCount++;

            double interestPerYear = newBalance - originalBalance;

            String interestPerYearString = df.format(interestPerYear);

            yearMap.put(yearCount, interestPerYearString);

            originalBalance = newBalance;

        } while (yearCount <= (numYears - 1));
        totalInterest = newBalance - startingBalance;
        //annualInterest.add(yearMap);
        String annualInterestString = yearMap.toString().replace("{", "").replace("}", "").trim();

        model.addAttribute("originalBalance", df.format(startingBalance));
        model.addAttribute("newBalance", df.format(newBalance));
        model.addAttribute("interestRate", intRate);
        model.addAttribute("interestEarned", df.format(totalInterest));
        model.addAttribute("years", df.format(numYears));
        model.addAttribute("periods", df.format(numPeriods));
        model.addAttribute("annualInterest", yearMap);

    } catch (NumberFormatException e) {
    }

    return "intercalcResponse";
    //<td><c:out value="${current.id}" /><td>
}

From source file:Main.java

/**
 * Tell whether the string contains an unsigned number.
 *///from   ww w. j ava2 s.  c o m
public static boolean isUnsignedNumber(String string) {
    String s = string.trim();
    if (s.length() < 1)
        return false;
    if (s.charAt(0) != '+' && s.charAt(0) != '-') {
        double value = 0;
        try {
            value = Double.parseDouble(s);
        } catch (NumberFormatException e) {
            return false;
        }
        return true;
    }
    return false;
}

From source file:de.qaware.chronix.solr.type.metric.functions.transformation.Divide.java

/**
 * Scales the time series by the given value
 *
 * @param value the divisor
 */
public Divide(String[] args) {
    this.value = Double.parseDouble(args[0]);
}

From source file:classpackage.ChartGalaxy.java

public static XYDataset createDataset() {
    LabeledXYDataset series = new LabeledXYDataset();
    List<String> vetorLinha = new ArrayList<>();
    List<List> lista = new ArrayList<>();
    try {/*from   w  w w .  j  a  v a2s. c  o m*/
        FileReader arq = new FileReader("Arquivo.txt");
        BufferedReader lerArq = new BufferedReader(arq);
        String linha = lerArq.readLine();
        while (linha != null) {
            String caracteres = " #@_\\/*|";
            String parts[] = linha.split("[" + Pattern.quote(caracteres) + "]");
            for (String i : parts) {
                vetorLinha.add(i);
            }
            lista.add(vetorLinha);
            vetorLinha = new ArrayList<>();
            linha = lerArq.readLine();
        }

        for (int i = 0; i < lista.size(); i++) {
            // for (int j = 0; j < vetorLinha.size(); j++) {
            double a = Double.parseDouble(lista.get(i).get(0).toString());
            double b = Double.parseDouble(lista.get(i).get(1).toString());
            String label = lista.get(i).get(2).toString();
            //System.out.println(lista.get(i).get(j));
            //}
            series.add(a, b, label);
        }

    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
    return series;
}