Example usage for java.lang Float toString

List of usage examples for java.lang Float toString

Introduction

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

Prototype

public static String toString(float f) 

Source Link

Document

Returns a string representation of the float argument.

Usage

From source file:com.cloudera.oryx.als.serving.web.EstimateForAnonymousServlet.java

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

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;// www .j  a v a2  s .  c om
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    String toItemID;
    Pair<String[], float[]> itemIDsAndValue;
    try {
        toItemID = pathComponents.next();
        itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    String[] itemIDs = itemIDsAndValue.getFirst();
    unescapeSlashHack(itemIDs);
    float[] values = itemIDsAndValue.getSecond();

    OryxRecommender recommender = getRecommender();
    try {
        float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values);
        Writer out = response.getWriter();
        out.write(Float.toString(estimate));
        out.write('\n');
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    }
}

From source file:com.controlj.addon.weather.noaa.DocumentLoader.java

public Document getForecast(float latitude, float longitude, int numDays, boolean isMetric)
        throws WeatherServiceException {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("lat", Float.toString(latitude));
    params.put("lon", Float.toString(longitude));
    params.put("startDate", dateFormat.format(new Date()));
    params.put("numDays", Integer.toString(numDays));
    params.put("format", "24 hourly");
    params.put("Unit", isMetric ? "m" : "e");
    try {/*  ww w  .ja v a2s  . com*/
        return new HTTPHelper().readDocument("http", "graphical.weather.gov", -1,
                "/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php", params);
    } catch (Exception e) {
        throw new WeatherServiceException(e.getMessage(), e);
    }
}

From source file:io.wcm.sling.commons.request.RequestParamTest.java

@SuppressWarnings("unused")
protected Map<String, Object> getParamMap() throws UnsupportedEncodingException {
    return ImmutableMap.<String, Object>builder().put(STRING_PARAM, new String[] { STRING_VALUE })
            .put(MULTI_STRING_PARAM, MULTI_STRING_VALUE)
            .put(INTEGER_PARAM, new String[] { Integer.toString(INTEGER_VALUE) })
            .put(LONG_PARAM, new String[] { Long.toString(LONG_VALUE) })
            .put(FLOAT_PARAM, new String[] { Float.toString(FLOAT_VALUE) })
            .put(DOUBLE_PARAM, new String[] { Double.toString(DOUBLE_VALUE) })
            .put(BOOLEAN_PARAM, new String[] { Boolean.toString(BOOLEAN_VALUE) })
            .put(ENUM_PARAM, new String[] { ENUM_VALUE.name() })
            .put(RequestParam.PARAMETER_FORMENCODING, new String[] { CharEncoding.UTF_8 }).build();
}

From source file:com.example.hbranciforte.trafficclient.DataTraffic.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_data_traffic);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }/*from  w w w.  j a  v a2  s . co m*/
    try {
        zone_info = new JSONObject((String) getIntent().getSerializableExtra("zone_info"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    EditText ed_fichas = (EditText) findViewById(R.id.fichas);
    ed_fichas.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            //float price = (float) 0.0;
            Integer time = 0;
            TextView txtvalor = (TextView) findViewById(R.id.valor);
            TextView txttiempo = (TextView) findViewById(R.id.txtTime);
            if (s.toString() != "") {
                try {
                    price = (float) zone_info.getDouble("unit_price") * Float.valueOf(s.toString());
                    time = zone_info.getInt("unit_time") * Integer.parseInt(s.toString());
                    txtvalor.setText("$ ".concat(Float.toString(price)));
                    txttiempo.setText(time.toString().concat(" min"));
                } catch (Exception e) {
                    Log.e("getting data0:", e.getMessage());
                    txttiempo.setText("0 min");
                    txtvalor.setText("$ 0.0");

                }
            }
        }
    });
}

From source file:nz.ac.auckland.lablet.script.components.ScriptComponentPotentialEnergy1View.java

public ScriptComponentPotentialEnergy1View(Context context, PotentialEnergy1 component) {
    super(context);
    this.component = component;

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.script_component_potential_energy_1, null, true);
    assert view != null;
    addView(view);/* www. j  a  va  2 s .c  om*/

    TextView massQuestionTextView = (TextView) view.findViewById(R.id.massQuestionTextView);
    assert massQuestionTextView != null;
    TextView heightQuestionTextView = (TextView) view.findViewById(R.id.heightQuestionTextView);
    assert heightQuestionTextView != null;
    TextView energyQuestionTextView = (TextView) view.findViewById(R.id.energyQuestionTextView);
    assert energyQuestionTextView != null;
    TextView pbjSandwichQuestionTextView = (TextView) view.findViewById(R.id.pbjSandwichQuestionTextView);
    assert pbjSandwichQuestionTextView != null;

    EditText massEditText = (EditText) view.findViewById(R.id.massEditText);
    assert massEditText != null;
    EditText heightEditText = (EditText) view.findViewById(R.id.heightEditText);
    assert heightEditText != null;
    EditText energyEditText = (EditText) view.findViewById(R.id.energyEditText);
    assert energyEditText != null;
    EditText pbjEditText = (EditText) view.findViewById(R.id.pbjEditText);
    assert pbjEditText != null;

    doneCheckBox = (CheckBox) view.findViewById(R.id.doneCheckBox);
    assert doneCheckBox != null;

    massQuestionTextView.setText(component.getMassQuestionText());
    heightQuestionTextView.setText(component.getHeightQuestionText());
    energyQuestionTextView.setText(component.getEnergyQuestionText());
    pbjSandwichQuestionTextView.setText(component.getPbjSandwichQuestionText());

    massEditText.setText(Float.toString(getMass()));
    heightEditText.setText(Float.toString(component.getHeight()));
    energyEditText.setText(Float.toString(component.getEnergy()));
    pbjEditText.setText(Float.toString(component.getPbjValue()));

    massEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            float value = 0;
            try {
                value = Float.parseFloat(editable.toString());
            } catch (NumberFormatException e) {
                System.out.println(e.getMessage());
            }
            setMass(value);
        }
    });
    heightEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            float value = 0;
            try {
                value = Float.parseFloat(editable.toString());
            } catch (NumberFormatException e) {
                System.out.println(e.getMessage());
            }
            setHeight(value);
        }
    });
    energyEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            float value = 0;
            try {
                value = Float.parseFloat(editable.toString());
            } catch (NumberFormatException e) {
                System.out.println(e.getMessage());
            }
            setEnergy(value);
        }
    });
    pbjEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {
            float value = 0;
            try {
                value = Float.parseFloat(editable.toString());
            } catch (NumberFormatException e) {
                System.out.println(e.getMessage());
            }
            setPbjValue(value);
        }
    });

    update();
}

From source file:ca.uhn.hl7v2.model.primitive.CommonTSTest.java

@BeforeClass
public static void setUp() throws Exception {
    year = 2002;/*w w  w  .  java 2 s.c  o  m*/
    month = 11;
    day = 30;
    hour = 11;
    minute = 23;
    second = 15;
    fractionalSecond = .1234F;

    offset = DataTypeUtil.getLocalGMTOffset();
    offsetStr = DataTypeUtil.preAppendZeroes(Math.abs(offset), 4);
    if (offset >= 0) {
        offsetStr = "+" + offsetStr;
    } else {
        offsetStr = "-" + offsetStr;
    }
    timeStamp = Integer.toString(year) + Integer.toString(month) + Integer.toString(day)
            + Integer.toString(hour) + Integer.toString(minute) + Integer.toString(second)
            + Float.toString(fractionalSecond).substring(1) + offsetStr;
    baseTime = Integer.toString(year) + Integer.toString(month) + Integer.toString(day) + Integer.toString(hour)
            + Integer.toString(minute) + Integer.toString(second)
            + Float.toString(fractionalSecond).substring(1);
}

From source file:com.climate.oada.dao.impl.DynamodbDAO.java

@Override
public boolean insert(LandUnit lu) {
    boolean retval = false;
    Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put(LandUnit.ID_ATTR_NAME, new AttributeValue(Long.toString(lu.getUnitId())));
    item.put(LandUnit.USER_ID_ATTR_NAME, new AttributeValue(Long.toString(lu.getUserId())));
    item.put(LandUnit.NAME_ATTR_NAME, new AttributeValue(lu.getName()));
    item.put(LandUnit.FARM_NAME_ATTR_NAME, new AttributeValue(lu.getFarmName()));
    item.put(LandUnit.CLIENT_NAME_ATTR_NAME, new AttributeValue(lu.getClientName()));
    item.put(LandUnit.ACRES_ATTR_NAME, new AttributeValue(Float.toString(lu.getAcres())));
    item.put(LandUnit.SOURCE_ATTR_NAME, new AttributeValue(lu.getSource()));
    item.put(LandUnit.OTHER_PROPS_ATTR_NAME, new AttributeValue(lu.getOtherProps()));
    item.put(LandUnit.GEOM_ATTR_NAME, new AttributeValue(lu.getWktBoundary()));
    PutItemRequest putItemRequest = new PutItemRequest(LANDUNIT_DYNAMO_DB_TABLE_NAME, item);
    try {//w  w w.java  2s .c o m
        PutItemResult putItemResult = dynamoDB.putItem(putItemRequest);
        LOG.debug("DDB Insert Result: " + putItemResult);
        retval = true;
    } catch (Exception e) {
        LOG.error("DDB Insert failed " + e.getMessage());
    }
    return retval;
}

From source file:com.laex.cg2d.model.joints.BEFrictionJoint.java

@Override
public Object getPropertyValue(Object id) {
    if (isMaxForceProp(id)) {
        return Float.toString(frictionJointDef.maxForce);
    }// w  w  w.jav  a 2 s. c om
    if (isMaxTorqueProp(id)) {
        return Float.toString(frictionJointDef.maxTorque);
    }
    return super.getPropertyValue(id);
}

From source file:net.myrrix.web.servlets.EstimateForAnonymousServlet.java

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

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;//  w w w .ja va 2 s  .co m
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    long toItemID;
    Pair<long[], float[]> itemIDsAndValue;
    try {
        toItemID = Long.parseLong(pathComponents.next());
        itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    } catch (NumberFormatException nfe) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    long[] itemIDs = itemIDsAndValue.getFirst();
    float[] values = itemIDsAndValue.getSecond();

    MyrrixRecommender recommender = getRecommender();
    try {
        float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values);
        Writer out = response.getWriter();
        out.write(Float.toString(estimate));
        out.write('\n');
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    } catch (TasteException te) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
        getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
    }
}

From source file:com.github.egonw.ops4j.Structures.java

public String tanimotoSimilarityFrom(String smiles, float treshold, int start, int count, Object... objects)
        throws ClientProtocolException, IOException, HttpException {
    Map<String, String> params = new HashMap<String, String>();
    params.put("searchOptions.Molecule", smiles);
    params.put("searchOptions.SimilarityType", "0"); // Tanimoto
    params.put("searchOptions.Threshold", Float.toString(treshold));
    params.put("resultOptions.Start", "" + Integer.toString(start));
    params.put("resultOptions.Count", "" + Integer.toString(count));
    return runRequest(server + "structure/similarity", params, objects);
}