Example usage for java.lang Float parseFloat

List of usage examples for java.lang Float parseFloat

Introduction

In this page you can find the example usage for java.lang Float parseFloat.

Prototype

public static float parseFloat(String s) throws NumberFormatException 

Source Link

Document

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

Usage

From source file:Main.java

public static Object getNamedElemValue(Element parent, String elementName, Class basicType, Object defaultVal) {
    String val = getNamedElemValue(parent, elementName);
    if (val == null) {
        return defaultVal;
    }//from   w  w w  .  j a  v  a  2 s  . c  o m

    try {
        if (Boolean.class.equals(basicType)) {
            return Boolean.parseBoolean(val);
        } else if (Integer.class.equals(basicType)) {
            return Integer.parseInt(val);
        } else if (Float.class.equals(basicType)) {
            return Float.parseFloat(val);
        } else if (Double.class.equals(basicType)) {
            return Double.parseDouble(val);
        } else
            return val;
    } catch (Exception e) {
        return defaultVal;
    }
}

From source file:com.surfs.storage.common.util.CmdUtils.java

public static Map<String, Object> command(String cmd) {
    Map<String, Object> resp = new HashMap<String, Object>();
    BufferedReader bufRead = null;
    try {//from   w  w  w  .j a  va  2  s  .  com
        //bufRead = executeCmdForReader(cmd);
        Process pro = Runtime.getRuntime().exec(cmd);
        bufRead = new BufferedReader(new InputStreamReader(pro.getInputStream(), "UTF-8"));
        // 0-success,others-failure
        int status = pro.waitFor();
        LogFactory.info("cmd:" + cmd);
        LogFactory.info("status:" + status);
        String response = null;
        while ((response = bufRead.readLine()) != null) {
            if (response.indexOf("avg") >= 0) {
                String[] ms = response.split("=")[1].split("\\/");
                resp.put("status", status);
                resp.put("latency", Float.parseFloat(ms[1]));
                LogFactory.info("latency:" + ms[1]);
                return resp;
            }
        }
    } catch (Exception e) {
        resp.put("status", 1);
        resp.put("response", "time out");
        return resp;
    } finally {
        if (bufRead != null)
            try {
                bufRead.close();
            } catch (Exception e) {
            }
    }
    resp.put("status", 1);
    resp.put("response", "time out");
    return resp;
}

From source file:org.jfree.chart.demo.AnnotationDemo1.java

private static XYSeriesCollection createDataset() {
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    try {//from  w w  w.  j av  a  2s . co  m
        BufferedReader bufferedreader = new BufferedReader(
                new InputStreamReader(AnnotationDemo1.class.getResourceAsStream("wtageinf.txt")));
        bufferedreader.readLine();
        bufferedreader.readLine();
        bufferedreader.readLine();
        bufferedreader.readLine();
        XYSeries xyseries = new XYSeries("P3", true, false);
        XYSeries xyseries1 = new XYSeries("P5", true, false);
        XYSeries xyseries2 = new XYSeries("P10", true, false);
        XYSeries xyseries3 = new XYSeries("P25", true, false);
        XYSeries xyseries4 = new XYSeries("P50", true, false);
        XYSeries xyseries5 = new XYSeries("P75", true, false);
        XYSeries xyseries6 = new XYSeries("P90", true, false);
        XYSeries xyseries7 = new XYSeries("P95", true, false);
        XYSeries xyseries8 = new XYSeries("P97", true, false);
        for (String s1 = bufferedreader.readLine(); s1 != null; s1 = bufferedreader.readLine()) {
            int i = Integer.parseInt(s1.substring(1, 8).trim());
            float f = Float.parseFloat(s1.substring(9, 17).trim());
            float f1 = Float.parseFloat(s1.substring(69, 86).trim());
            float f2 = Float.parseFloat(s1.substring(87, 103).trim());
            float f3 = Float.parseFloat(s1.substring(104, 122).trim());
            float f4 = Float.parseFloat(s1.substring(123, 140).trim());
            float f5 = Float.parseFloat(s1.substring(141, 158).trim());
            float f6 = Float.parseFloat(s1.substring(159, 176).trim());
            float f7 = Float.parseFloat(s1.substring(177, 193).trim());
            float f8 = Float.parseFloat(s1.substring(194, 212).trim());
            float f9 = Float.parseFloat(s1.substring(212, s1.length()).trim());
            if (i == 1) {
                xyseries.add(f, f1);
                xyseries1.add(f, f2);
                xyseries2.add(f, f3);
                xyseries3.add(f, f4);
                xyseries4.add(f, f5);
                xyseries5.add(f, f6);
                xyseries6.add(f, f7);
                xyseries7.add(f, f8);
                xyseries8.add(f, f9);
            }
        }

        xyseriescollection.addSeries(xyseries);
        xyseriescollection.addSeries(xyseries1);
        xyseriescollection.addSeries(xyseries2);
        xyseriescollection.addSeries(xyseries3);
        xyseriescollection.addSeries(xyseries4);
        xyseriescollection.addSeries(xyseries5);
        xyseriescollection.addSeries(xyseries6);
        xyseriescollection.addSeries(xyseries7);
        xyseriescollection.addSeries(xyseries8);
    } catch (FileNotFoundException filenotfoundexception) {
        System.err.println(filenotfoundexception);
    } catch (IOException ioexception) {
        System.err.println(ioexception);
    }
    return xyseriescollection;
}

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.FloatDataConverter.java

@Override
public Float stringToValue(String rawData) {
    return StringUtils.isNotEmpty(rawData) ? Float.parseFloat(rawData.replace(",", ".")) : null;
}

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

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

    try {/*from w w w  . j a  v  a  2 s  .  co m*/

        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:com.ceutecsps.adminplanilla.documents.Actividad.java

public String getTotal() {
    if (!StringUtils.isBlank(trabajoRealizado)) {
        float workDone = Float.parseFloat(trabajoRealizado);
        float laborWorth = this.labor.getPrecio();
        return String.valueOf((workDone * laborWorth));
    } else {//www  .  j a va2 s  .com
        return "";
    }
}

From source file:com.stealthyone.mcb.stbukkitlib.utils.LocationUtils.java

/**
 * Converts a string to a location./*from  w  w  w  .j av a2s . c  o  m*/
 * Form: 'worldName,x,y,z,yaw,pitch'
 *
 * @param input String to convert.
 * @return String in location form.
 * @throws java.lang.IllegalArgumentException Thrown if the input string is not a valid location.
 */
public static Location stringToLocation(String input) {
    Validate.notNull(input, "Input cannot be null.");

    String[] split = input.split(",");
    if (split.length < 6)
        throw new IllegalArgumentException("Invalid input");

    return new Location(Bukkit.getWorld(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]),
            Double.parseDouble(split[3]), Float.parseFloat(split[4]), Float.parseFloat(split[5]));
}

From source file:com.impetus.kundera.utils.NumericUtils.java

/**
 *  Check if zero/*from   w w w . j a va 2 s  .co  m*/
 * @param value        value string
 * @param valueClazz   value class 
 * @return             
 */
public static final boolean checkIfZero(String value, Class valueClazz) {
    boolean returnValue = false;
    if (value != null && NumberUtils.isNumber(value) && numberTypes.get(valueClazz) != null) {
        switch (numberTypes.get(valueClazz)) {

        case INTEGER:
            returnValue = Integer.parseInt(value) == (NumberUtils.INTEGER_ZERO);
            break;

        case FLOAT:
            returnValue = Float.parseFloat(value) == (NumberUtils.FLOAT_ZERO);
            break;

        case LONG:
            returnValue = Long.parseLong(value) == (NumberUtils.LONG_ZERO);
            break;

        case BIGDECIMAL:
            returnValue = new BigDecimal(value) == (BigDecimal.ZERO);
            break;

        case BIGINTEGER:
            returnValue = new BigInteger(value) == (BigInteger.ZERO);
            break;

        case SHORT:
            returnValue = new Short(value) == (NumberUtils.SHORT_ZERO);
            break;
        }
    }

    return returnValue;
}

From source file:com.odoo.orm.ODataRow.java

public Float getFloat(String key) {
    return Float.parseFloat(_data.get(key).toString());
}

From source file:Main.java

public static int getStationFromUI(TextView textView) {
    int station = 0;
    float frequency = 0;
    String frequencyStr = textView.getText().toString();
    try {// www. j  av  a  2s  . c  o  m
        frequency = Float.parseFloat(frequencyStr);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    station = (int) (frequency * CONVERT_RATE);
    return station;
}