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:mase.neat.NEATSerializer.java

public static NEATNeuralNet deserialize(String ser) {
    String[] split = ser.split(",");
    double[] stuff = new double[split.length];
    for (int i = 0; i < stuff.length; i++) {
        stuff[i] = Double.parseDouble(split[i]);
    }/*from  w w  w .  ja  va2 s  . c  o m*/
    return deserialize(stuff);
}

From source file:com.icloud.framework.core.util.FBUtilities.java

/**
 * Parses a string representing either a fraction, absolute value or
 * percentage./* ww w  .j  a v a 2s  .  c  om*/
 */
public static double parseDoubleOrPercent(String value) {
    if (value.endsWith("%")) {
        return Double.parseDouble(value.substring(0, value.length() - 1)) / 100;
    } else {
        return Double.parseDouble(value);
    }
}

From source file:com.veera.secondarysort.demo2.SsMapper.java

@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String[] tokens = value.toString().split(",");

    String symbol = tokens[0].trim();
    Long timestamp = Long.parseLong(tokens[1].trim());
    Double v = Double.parseDouble(tokens[2].trim());

    StockKey stockKey = new StockKey(symbol, timestamp);
    DoubleWritable stockValue = new DoubleWritable(v);

    context.write(stockKey, stockValue);
    _log.debug(stockKey.toString() + " => " + stockValue.toString());
}

From source file:it.unibas.spicy.persistence.Types.java

public static Object getTypedValue(String type, Object value) throws DAOException {
    if (value == null || value.toString().equalsIgnoreCase("NULL")) {
        return NullValueFactory.getNullValue();
    }//from  ww  w .  j a  v  a 2  s. c  om
    if (type.equals(BOOLEAN)) {
        return Boolean.parseBoolean(value.toString());
    }
    if (type.equals(STRING)) {
        return value.toString();
    }
    if (type.equals(INTEGER)) {
        try {
            return Integer.parseInt(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(DOUBLE)) {
        try {
            return Double.parseDouble(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(FLOAT)) {
        try {
            return Float.parseFloat(value.toString());
        } catch (NumberFormatException ex) {
            logger.error(ex);
            throw new DAOException(ex.getMessage());
        }
    }
    if (type.equals(DATE) || type.equals(DATETIME)) {
        return value.toString();
        //            try {
        //                return DateFormat.getDateInstance().parse(value.toString());
        //            } catch (ParseException ex) {
        //                logger.error(ex);
        //                throw new DAOException(ex.getMessage());
        //            }
    }
    return value.toString();
}

From source file:fr.mycellar.interfaces.web.services.FilterCouple.java

/**
 * Default constructor.//w w  w  .j a  va2 s  .c  o m
 * 
 * @param couple
 */
public FilterCouple(String couple) {
    property = couple.substring(0, couple.indexOf(","));
    String value = couple.substring(couple.indexOf(",") + 1);
    Object result = null;
    try {
        result = Long.parseLong(value);
    } catch (Exception e) {
    }
    if (result == null) {
        try {
            result = Double.parseDouble(value);
        } catch (Exception e) {
        }
    }
    if (result == null) {
        try {
            result = LocalDateTime.parse(value);
        } catch (Exception e) {
        }
    }
    if (result == null) {
        result = value;
    }
    filter = result;
}

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

/**
 * Constructs the add transformation//from w  w  w  .j a  v  a 2s.c  o  m
 *
 * @param value the value that is added to each measurement
 */
public Add(String[] args) {
    this.value = Double.parseDouble(args[0]);
}

From source file:facebook4j.auth.AccessToken.java

public AccessToken(HttpResponse res) throws FacebookException {
    // see: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#apiversiondebug
    String version = res.getResponseHeader("facebook-api-version");
    if (Double.parseDouble(version.substring(1)) < 2.3) {
        parseQueryString(res.asString());
        return;/*w w  w . j  ava2  s  . com*/
    }
    JSONObject json = res.asJSONObject();
    this.token = getRawString("access_token", json);
    this.type = getRawString("token_type", json);
    this.expires = getLong("expires_in", json);
}

From source file:org.opendatakit.database.utilities.KeyValueStoreUtils.java

public static Double getNumber(KeyValueStoreEntry entry) throws IllegalArgumentException {
    if (entry == null) {
        return null;
    }/*from  w  w w.j  a v  a  2  s  .  c  o  m*/
    if (!entry.type.equals(ElementDataType.number.name())) {
        throw new IllegalArgumentException("requested number entry for " + "key: " + entry.key
                + ", but the corresponding entry in the store was " + "not of type: "
                + ElementDataType.number.name());
    }
    try {
        return Double.parseDouble(entry.value);
    } catch (NumberFormatException ignored) {
        throw new IllegalArgumentException(
                "requested int entry for " + "key: " + entry.key + ", but the value in the store failed to "
                        + "parse to type: " + ElementDataType.number.name());
    }
}

From source file:de.cubicvoxel.workspacefx.field.FloatField.java

public FloatField() {
    textProperty().addListener(((observable, oldValue, newValue) -> {
        if (StringUtils.isEmpty(newValue)) {
            floatValue = null;/*from w w  w  .  ja v  a 2s  .c o m*/
        } else {
            try {
                floatValue = Double.parseDouble(newValue);
            } catch (NumberFormatException e) {
                setText(oldValue);
                floatValue = Double.parseDouble(oldValue);
            }
        }
    }));
}

From source file:com.ci6225.marketzone.validation.FormValidation.java

public boolean validateAddProduct(String name, String description, String quantity, String unitPrice,
        FileItem image) {/*from   www. j a v  a  2  s. c o m*/

    boolean isValid = true;

    isValid = setInputErrorMessage(name, "Product Name", 30, 3);
    isValid = setInputErrorMessage(description, "Description", 400, 3);

    if (quantity.trim().length() == 0) {
        errorMessages.add("Please provide your quantity");
        isValid = false;
    } else if (!isValidInt(quantity) || Integer.parseInt(quantity) <= 0) {
        errorMessages.add("Please provide valid quantity");
        isValid = false;
    }

    if (unitPrice.trim().length() == 0) {
        errorMessages.add("Please provide your quantity");
        isValid = false;
    } else if (!isValidDouble(unitPrice) || Double.parseDouble(unitPrice) <= 0) {
        errorMessages.add("Please provide valid price");
        isValid = false;
    }

    /*if (image == null) {
    errorMessages.add("Please upload product image");
    isValid = false;
    }*/
    return isValid;
}