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.autentia.tnt.converter.MinuteToHourConverter.java

public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
    log.debug("getAsObject - value=" + value);

    if (value == null) {
        return null;
    } else {//from   w  ww. ja va2  s  .  c om
        try {
            double val = Double.parseDouble(value.replaceAll(",", "."));
            return Integer.valueOf((int) (val * 60));
        } catch (NumberFormatException e) {
            throw new ConverterException("Error converting minutes: " + value, e);
        }
    }
}

From source file:com.anhth12.lambda.common.math.VectorMath.java

public static double[] parseVector(String[] values) {
    double[] doubles = new double[values.length];
    for (int i = 0; i < values.length; i++) {
        doubles[i] = Double.parseDouble(values[i]);
    }/*from   www .  j ava 2s  .  c om*/
    return doubles;
}

From source file:com.espertech.esper.example.servershell.SampleJMSMessageListener.java

public void onMessage(Message message) {
    BytesMessage bytesMsg = (BytesMessage) message;
    String body = getBody(bytesMsg);

    String[] payload = body.split(",");
    String ipAddress = payload[0];
    double duration = Double.parseDouble(payload[1]);

    SampleEvent theEvent = new SampleEvent(ipAddress, duration);

    engine.sendEvent(theEvent);/*ww w  . j  a v  a  2  s . c  o m*/
    count++;
}

From source file:bigdataproject.ReadDataSet.java

public void readFromFile() {
    String csvFile = "wiki4HE2.csv";
    BufferedReader br = null;//  w ww  .j  a  v  a2s  .c om
    String line;
    String cvsSplitBy = ";";
    try {
        br = new BufferedReader(new FileReader(csvFile));
        for (int i = 0; i < N_rows; i++) {
            line = br.readLine();
            if (line != null) {
                String[] tokens = line.split(cvsSplitBy);
                double[] row = new double[N_columns];
                double missing = 0.0;
                double value;
                for (int j = 0; j < N_columns; j++) {
                    if (!tokens[j].equals("?")) {
                        value = Double.parseDouble(tokens[j]);
                    } else {
                        value = -1.0;
                        missing++;
                    }
                    row[j] = value;
                }
                double percentage = (missing / N_columns) * 100;
                if (percentage < 10.0) {
                    samples.put(i, row);
                }
            }
        }
    } catch (IOException | NumberFormatException e) {
        System.err.println("File Not Found or bad file format\n"
                + "Make sure the file named wiki4HE2.csv is on the same path of the executable jar\n" + e);
        System.exit(0);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                System.err.println("Something worng happened with the csv file\n" + e);
                System.exit(0);
            }
        }
    }
}

From source file:com.espe.distribuidas.telefonia.socket.ServerSocket.java

@OnMessage
public String handleMessage(String message) {
    System.out.println("mesaje: " + message);

    String[] datos = StringUtils.split(message, "|");

    String telefono = datos[0];/*from w  ww.  j  a  va  2  s.  co m*/
    double valor = Double.parseDouble(datos[1]);

    System.out.println(telefono + " ------ " + valor);

    Cliente c = this.clienteServicio.obtenerTelefonoPorNumero(telefono);

    if (c != null) {
        message = "cliente SI existe";
        System.out.println(message + " _> " + c.toString());

        Transaccion t = new Transaccion();
        t.setCliente(c);
        t.setFechaRecarga(new Date());
        t.setMonto(valor);
        double newSaldo = valor + c.getSaldo();
        t.setSaldoActual(newSaldo);

        this.transaccionServicio.insertarTransaccion(t);
        this.clienteServicio.actualizarSaldo(telefono, newSaldo);

        System.out.println("Transaccion realizada con exito " + t.toString());
        message = "OK";
    } else {
        message = "cliente NO existe";
        System.out.println(message);
        message = "NO";
    }

    String replyMessage = message;
    System.out.println("Mensaje  enviar:" + replyMessage);
    return replyMessage;
}

From source file:com.jkoolcloud.tnt4j.streams.utils.DoubleRange.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof Number) {
        return inRange(((Number) obj).doubleValue());
    }//from   w ww . java 2 s  .c o  m

    if (obj instanceof String) {
        try {
            return inRange(Double.parseDouble((String) obj));
        } catch (NumberFormatException exc) {
        }
    }

    return super.equals(obj);
}

From source file:Data.Utilities.java

public static List<Cluster<DoublePoint>> DBSCANClusterer(ArrayList<StayPoint> stayPoints, Double eParam,
        Integer minClust) {/*from ww  w.  ja v  a  2  s.  co  m*/

    DBSCANClusterer dbscan = new DBSCANClusterer(eParam, minClust);

    ArrayList<DoublePoint> input = new ArrayList<DoublePoint>();

    for (StayPoint st : stayPoints) {
        double coord[] = new double[2];
        coord[0] = Double.parseDouble(st.getLatitude());
        coord[1] = Double.parseDouble(st.getLongitude());
        input.add(new DoublePoint(coord));
    }

    List<Cluster<DoublePoint>> cluster = dbscan.cluster(input);

    return cluster;
}

From source file:ml.shifu.shifu.core.binning.NativeBinning.java

@Override
public void addData(String val) {
    String fval = StringUtils.trimToEmpty(val);
    if (!isMissingVal(fval)) {
        double dval = 0;

        try {//from ww  w  .  j av a 2  s .c o  m
            dval = Double.parseDouble(fval);
        } catch (NumberFormatException e) {
            super.incInvalidValCnt();
            return;
        }
        array.add(dval);
    } else {
        super.incMissingValCnt();
    }
}

From source file:trinhm.controller.StaffController.java

@RequestMapping("edit")
public String edit(HttpServletRequest request, ModelMap model) {
    String Id = request.getParameter("txtMaNV");

    String Name = request.getParameter("txtName");
    String Gender = request.getParameter("txtGender");
    String Birthday = request.getParameter("txtBirthday");
    String Photo = request.getParameter("txtPhoto");
    String Email = request.getParameter("txtEmail");
    String Phone = request.getParameter("txtPhone");
    double Salary = Double.parseDouble(request.getParameter("txtSalary"));
    String Notes = request.getParameter("txtNotes");
    String DepartId = request.getParameter("txtDepartId");
    Staff nv = new Staff(Id, Name, Gender, Birthday, Photo, Email, Phone, Salary, Notes, DepartId);
    model.addAttribute("staff", nv);

    List<Staff> list = new ArrayList<Staff>();
    list = StaffModel.showProduct("");
    model.addAttribute("listStaff", list);
    return "staff";
}

From source file:com.libresoft.apps.ARviewer.Utils.GeoNames.AltitudeManager.java

public static double getAltitudeFromLatLong(float latitude, float longitude) {
    double altitude = AltitudeManager.NO_ALTITUDE_VALUE;

    String data = "?lat=" + Float.toString(latitude) + "&lng=" + Float.toString(longitude);

    try {//Aster
        DefaultHttpClient httpclient = new DefaultHttpClient();

        HttpGet httpGet = new HttpGet(URL + data);

        HttpResponse response = httpclient.execute(httpGet);

        HttpEntity entity = response.getEntity();

        String str = convertStreamToString(entity.getContent());

        Log.d("GeoNames: ", str);

        altitude = Double.parseDouble(str);

        if (altitude < 0)
            altitude = 0;/*from www. j a  v  a  2 s . co  m*/

        return altitude;

    } catch (Exception e) {
        Log.e("GeoNames: ", e.getMessage());
        return emergencyService(data);
    }
}