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:com.shoylpik.controller.AddProduct.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String SAVE_DIRECTORY = "shoylpik_images";
    String absolutePath = request.getServletContext().getRealPath("");
    String savePath = absolutePath + File.separator + SAVE_DIRECTORY;

    File imageSaveDirectory = new File(savePath);
    if (!imageSaveDirectory.exists()) {
        imageSaveDirectory.mkdir();//from  w  w  w  .j a v a2 s  .c o m
    }

    System.out.println("imageSaveDirectory.getAbsolutePath(): " + imageSaveDirectory.getAbsolutePath());
    String fileName = null;
    //Get all the parts from request and write it to the file on server
    for (Part part : request.getParts()) {
        fileName = getFileName(part);
        System.out.println("fileName: " + fileName);
        part.write(savePath + File.separator + fileName);
    }

    try {
        System.out.println("savePath : " + savePath);
        String imageName = request.getParameter("IPimage");
        System.out.println("imageName: " + imageName);
        Part filePart = request.getPart("IPimage");
        InputStream imageInputStream = filePart.getInputStream();

        Product product = new Product();
        product.setProductId(Integer.parseInt(request.getParameter("IPID")));
        product.setProductName(request.getParameter("IPname"));
        product.setProductImageName(imageName);
        product.setProductCategory(request.getParameter("IPcat"));
        product.setProductPrice(Float.parseFloat(request.getParameter("IPprice")));
        product.setProductQuantity(Integer.parseInt(request.getParameter("IPQuant")));

        ProductBean pBean = new ProductBean();
        pBean.addProduct(product);

        String fullImagePath = savePath + File.separator + imageName;
        File file = new File(fullImagePath);
        System.out.println("fullImagePath : " + fullImagePath);
        FileOutputStream fos = new FileOutputStream(file);

        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (!isMultipart) {

        } else {
            System.out.println("Inside else");
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;

            try {
                items = upload.parseRequest(request);
            } catch (FileUploadException e) {

            }
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                System.out.println("Inside while");
                FileItem item = (FileItem) items.iterator();
                item.write(file);
            }
        }
    } catch (SQLException ex) {
        Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex);
    }
    response.sendRedirect("AdministrationPage.jsp");
}

From source file:com.ratebeer.android.api.command.SearchBeersCommand.java

@Override
protected void parse(JSONArray json) throws JSONException {
    results = new ArrayList<BeerSearchResult>();
    for (int i = 0; i < json.length(); i++) {
        JSONObject result = json.getJSONObject(i);
        String pctl = result.getString("OverallPctl");
        results.add(new BeerSearchResult(Integer.parseInt(result.getString("BeerID")),
                HttpHelper.cleanHtml(result
                        // TODO: This should parse as a double and be displayed as integer instead
                        .getString("BeerName")),
                (pctl.equals("null") ? -1 : Float.parseFloat(pctl)),
                Integer.parseInt(result.getString("RateCount")), result.getInt("IsRated") == 1,
                result.getBoolean("IsAlias"), result.getBoolean("Retired")));
    }//from  w w  w  .j av  a 2s  .  c om
    Collections.sort(results, new BeerSearchResultComparator(SortBy.Name));

}

From source file:com.abid_mujtaba.bitcoin.tracker.services.FetchPriceService.java

public static String get_btc_price() throws NetworkException {
    final String url = "https://www.bitstamp.net/api/ticker/";

    HttpClient client = getHttpClient();
    HttpGet get = new HttpGet(url);

    long time = System.currentTimeMillis() / 1000;
    float buy_price, sell_price;

    try {/*  w ww.j a  va 2 s .c o m*/
        // Fetch buy price from coinbase backend
        HttpResponse response = client.execute(get);

        JSONObject jResponse = new JSONObject(HttpResponseToString(response));
        buy_price = Float.parseFloat(jResponse.getString("ask"));
        sell_price = Float.parseFloat(jResponse.getString("bid"));

        return String.format("%d %.2f %.2f", time, buy_price, sell_price);
    } catch (IOException e) {
        throw new NetworkException("GET failure.", e);
    } catch (JSONException e) {
        throw new NetworkException("Failed to convert GET response to JSON.", e);
    }
}

From source file:Data.Player.java

public void nhlnumbers(String input) {
    temp = input.split("<td>");

    String pdata[] = temp[0].split(":");
    name = pdata[4].substring(pdata[4].indexOf(">") + 1, pdata[4].indexOf("</")).split(", ")[1] + " "
            + pdata[4].substring(pdata[4].indexOf(">") + 1, pdata[4].indexOf("</")).split(", ")[0];
    fixname();/*from   w  ww  . ja  v  a2  s . co m*/
    BTN_index = name.toLowerCase().replaceAll("[^A-Za-z]", "");

    jersey = NumberUtils.toInt(pdata[1].substring(1, pdata[1].indexOf("&")));

    position = pdata[3].substring(1, 2);
    age = NumberUtils.toInt(pdata[4].substring(1, pdata[4].indexOf("&")));

    if (!temp[1].contains("unknown")) {
        team = temp[1].substring(temp[1].indexOf(">") + 1, temp[1].indexOf("</"));
    }

    gp = NumberUtils.toInt(temp[2].substring(1, temp[2].indexOf("<") - 1));
    goals = NumberUtils.toInt(temp[3].substring(1, temp[3].indexOf("<") - 1));
    assists = NumberUtils.toInt(temp[4].substring(1, temp[4].indexOf("<") - 1));
    points = NumberUtils.toInt(temp[5].substring(1, temp[5].indexOf("<") - 1));
    plusminus = NumberUtils.toInt(temp[6].substring(1, temp[6].indexOf("<") - 1));
    pim = NumberUtils.toInt(temp[7].substring(1, temp[7].indexOf("<") - 1));
    hits = NumberUtils.toInt(temp[8].substring(1, temp[8].indexOf("<") - 1));
    blocks = NumberUtils.toInt(temp[9].substring(1, temp[9].indexOf("<") - 1));
    ppg = NumberUtils.toInt(temp[10].substring(1, temp[10].indexOf("<") - 1));
    ppa = NumberUtils.toInt(temp[11].substring(1, temp[11].indexOf("<") - 1));
    shg = NumberUtils.toInt(temp[12].substring(1, temp[12].indexOf("<") - 1));
    sha = NumberUtils.toInt(temp[13].substring(1, temp[13].indexOf("<") - 1));
    stp = ppg + ppa + shg + sha;
    esp = points - stp;
    gwg = NumberUtils.toInt(temp[14].substring(1, temp[14].indexOf("<") - 1));
    sog = NumberUtils.toInt(temp[15].substring(1, temp[15].indexOf("<") - 1));
    sht_pcnt = round(Float.parseFloat(temp[16].substring(1, temp[16].indexOf("<") - 1)) * 100, 2);
}

From source file:io.galeb.undertow.handlers.HeaderMetricsListener.java

public int getResponseTime(HttpServerExchange exchange) {
    return Math.round(Float.parseFloat(responseTimeAttribute.readAttribute(exchange)));
}

From source file:com.kagilum.plugins.icescrum.IceScrumSession.java

public boolean isConnect() {
    GetMethod method = new GetMethod(settings.getUrl() + "/version/");
    if (executeMethod(method)) {
        try {//from   www. java2s.  c o  m
            String version = body;
            if (version.isEmpty()) {
                throw new IOException(Messages.IceScrumSession_icescrum_http_notfound());
            }
            if (version.startsWith("7.")) {
                method = new GetMethod(settings.getUrl() + "/ws/p/" + settings.getPkey() + "/build");
                return executeMethod(method, 200);
            } else {
                //Only Pro version contains build business object
                if (!version.contains("Pro")) {
                    throw new IOException(Messages.IceScrumSession_only_pro_version());
                }
                //Got R6#5.1 Pro (Cloud) -> 6.51 in order to compare float
                version = version.replaceAll(" Pro", "").replaceAll(" Cloud", "").replaceAll("R", "")
                        .replaceAll("\\.", "").replaceAll("#", ".");
                if (version.length() == 3) {
                    version = version.replaceAll("\\.", ".0");
                }
                if (Float.parseFloat(version) < REQUIRED_VERSION) {
                    throw new IOException(Messages.IceScrumSession_not_compatible_version());
                }
                method = new GetMethod(settings.getUrl() + "/ws/p/" + settings.getPkey() + "/task");
                return executeMethod(method);
            }
        } catch (IOException e) {
            httpError = e.getMessage();
        }
    }
    return false;
}

From source file:indexer.DocVector.java

public DocVector(String line, int id, int numDimensions, int numIntervals) {
    String[] tokens = line.split("\\s+");
    this.docName = tokens[0];
    this.id = id;
    this.numDimensions = numDimensions;

    assert (tokens.length - 1 == numDimensions);
    x = new float[numDimensions];

    StringBuffer buff = new StringBuffer();
    for (int i = 1; i < tokens.length; i++) {
        x[i - 1] = Float.parseFloat(tokens[i]);
        buff.append(tokens[i]).append(" ");
    }//ww  w. j  a  v a  2s. c om
    DocVector.numIntervals = numIntervals;
    quantized = quantize();
}

From source file:net.sf.jasperreports.engine.xml.JRPrintTextFactory.java

@Override
public Object createObject(Attributes atts) {
    JasperPrint jasperPrint = (JasperPrint) digester.peek(digester.getCount() - 2);

    JRBasePrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());

    HorizontalTextAlignEnum horizontalTextAlign = HorizontalTextAlignEnum
            .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_textAlignment));
    if (horizontalTextAlign != null) {
        text.setHorizontalTextAlign(horizontalTextAlign);
    }/*from w  ww  .j a v  a 2s  . com*/

    VerticalTextAlignEnum verticalTextAlign = VerticalTextAlignEnum
            .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_verticalAlignment));
    if (verticalTextAlign != null) {
        text.setVerticalTextAlign(verticalTextAlign);
    }

    RotationEnum rotation = RotationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
    if (rotation != null) {
        text.setRotation(rotation);
    }

    RunDirectionEnum runDirection = RunDirectionEnum
            .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_runDirection));
    if (runDirection != null) {
        text.setRunDirection(runDirection);
    }

    String textHeight = atts.getValue(JRXmlConstants.ATTRIBUTE_textHeight);
    if (textHeight != null && textHeight.length() > 0) {
        text.setTextHeight(Float.parseFloat(textHeight));
    }

    LineSpacingEnum lineSpacing = LineSpacingEnum
            .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
    if (lineSpacing != null) {
        if (log.isWarnEnabled()) {
            log.warn("The 'lineSpacing' attribute is deprecated. Use the <paragraph> tag instead.");
        }
        text.getParagraph().setLineSpacing(lineSpacing);
    }

    text.setMarkup(atts.getValue(JRXmlConstants.ATTRIBUTE_markup));

    String isStyledText = atts.getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
    if (isStyledText != null && isStyledText.length() > 0) {
        if (log.isWarnEnabled()) {
            log.warn("The 'isStyledText' attribute is deprecated. Use the 'markup' attribute instead.");
        }

        text.setMarkup(
                Boolean.valueOf(isStyledText) ? JRCommonText.MARKUP_STYLED_TEXT : JRCommonText.MARKUP_NONE);
    }

    String lineSpacingFactor = atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacingFactor);
    if (lineSpacingFactor != null && lineSpacingFactor.length() > 0) {
        text.setLineSpacingFactor(Float.parseFloat(lineSpacingFactor));
    }

    String leadingOffset = atts.getValue(JRXmlConstants.ATTRIBUTE_leadingOffset);
    if (leadingOffset != null && leadingOffset.length() > 0) {
        text.setLeadingOffset(Float.parseFloat(leadingOffset));
    }

    text.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType));
    text.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));
    text.setAnchorName(atts.getValue(JRXmlConstants.ATTRIBUTE_anchorName));
    text.setHyperlinkReference(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkReference));
    text.setHyperlinkAnchor(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkAnchor));

    String hyperlinkPage = atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkPage);
    if (hyperlinkPage != null) {
        text.setHyperlinkPage(Integer.valueOf(hyperlinkPage));
    }

    text.setHyperlinkTooltip(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTooltip));

    String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
    if (bookmarkLevelAttr != null) {
        text.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
    }

    String valueClass = atts.getValue(JRXmlConstants.ATTRIBUTE_valueClass);
    if (valueClass != null) {
        text.setValueClassName(valueClass);
    }

    String pattern = atts.getValue(JRXmlConstants.ATTRIBUTE_pattern);
    if (pattern != null) {
        text.setPattern(pattern);
    }

    String formatFactoryClass = atts.getValue(JRXmlConstants.ATTRIBUTE_formatFactoryClass);
    if (formatFactoryClass != null) {
        text.setFormatFactoryClass(formatFactoryClass);
    }

    String locale = atts.getValue(JRXmlConstants.ATTRIBUTE_locale);
    if (locale != null) {
        text.setLocaleCode(locale);
    }

    String timezone = atts.getValue(JRXmlConstants.ATTRIBUTE_timezone);
    if (timezone != null) {
        text.setTimeZoneId(timezone);
    }

    return text;
}

From source file:neembuu.uploader.external.CheckMajorUpdate.java

/**
 * /*from   w ww .j a  va 2s. c om*/
 * @param str
 * @return the value between <version> and </version> tags from the specified string.
 */
public static float getVersionFromXML(String str) {
    float ver = 0;
    try {
        String start = "<version>";
        String end = "</version>";

        str = str.substring(str.indexOf(start) + start.length());

        str = str.substring(0, str.indexOf(end));
        ver = Float.parseFloat(str);
    } catch (Exception any) {
        NULogger.getLogger().severe(any.toString());
    }
    return ver;
}

From source file:blue.soundObject.pianoRoll.Scale.java

private static float getMultiplier(String lineInput) {
    float multiplier = 0.0f;

    String line = removeComments(lineInput);

    if (line.indexOf('/') > -1) {

        String[] vals = line.split("/");
        multiplier = Float.parseFloat(vals[0]) / Float.parseFloat(vals[1]);
    } else if (line.indexOf('.') > -1) {
        float cents = Float.parseFloat(line);
        multiplier = (float) Math.pow(2, cents / 1200);
    } else { // assume ratio
        multiplier = Float.parseFloat(line);
    }/*from  www.  j  a v a 2 s . c  om*/

    return multiplier;
}