List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:Main.java
public static float getValueByFloat(String value) { float result = 0; if (value != null && !value.equals("")) { try {//from ww w . j a v a 2s . c om result = Float.valueOf(value); } catch (NumberFormatException e) { } } return result; }
From source file:Main.java
public static float getRating(String rate) { if (rate != null) { if (rate.length() == 2) { return Float.valueOf(rate) / 10; } else {//from ww w . j av a2 s .c o m return Float.valueOf(rate); } } return 0; }
From source file:Main.java
public static String transferTP(String oldValue) { String newValue = oldValue;/*from ww w . j a v a 2s .c o m*/ float ov = Float.valueOf(oldValue) / 1000; Formatter fmt = new Formatter(); if (ov >= 100) { newValue = String.valueOf(Math.floor(ov + 0.5)); } else if (ov > 10) { newValue = fmt.format("%.1f", ov).toString(); } else { newValue = fmt.format("%.2f", ov).toString(); } return newValue; }
From source file:Main.java
public static float[] toFloatList(String str) { String[] strs = str.split(","); float[] floats = new float[strs.length]; for (int i = 0; i < strs.length; i++) floats[i] = Float.valueOf(strs[i]); return floats; }
From source file:Main.java
public static float formatFloat(float value) { DecimalFormat df = new DecimalFormat(); String style = "0.0"; df.applyPattern(style);//from w w w. ja v a2 s .c o m return Float.valueOf(df.format(value)); }
From source file:Main.java
public static float getJsonFloatValue(JSONObject jsonObject, String key, float defaultValue) { try {/*from w w w . ja v a 2 s. c o m*/ if (jsonObject != null && jsonObject.has(key)) { return Float.valueOf(jsonObject.getString(key)); } } catch (Exception e) { return defaultValue; } return defaultValue; }
From source file:Main.java
private static float getFloatFromString(String s) { if (s != null && !s.trim().equals("")) { s = s.replaceAll(",", ""); try {/*from w w w.ja v a 2 s.c o m*/ if (s.endsWith("%")) { return Float.valueOf(s.substring(0, s.length() - 1)); } else { return Float.valueOf(s); } } catch (NumberFormatException e) { } } return 0; }
From source file:Main.java
public static float toLength(String str, float scale) { return Float.valueOf(str) / scale; }
From source file:Main.java
static void checkPositiveOrZero(float number, String name) { if (number < 0.0F) throw new IllegalArgumentException( String.format("%s %d must be positive", new Object[] { name, Float.valueOf(number) })); }
From source file:Main.java
public static float precision(int decimalPlace, float val) { if (Float.isNaN(val)) { return 0.0f; }// w w w .j a v a 2 s .c o m String str = String.format(Locale.ENGLISH, "%." + decimalPlace + 'f', val); return Float.valueOf(str); }