List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:Main.java
public static void setFloatContent(Element elem, float value) { setTextContent(elem, Float.toString(value)); }
From source file:Main.java
private static Float precision(int decimalPlace, Float d) { BigDecimal bd = new BigDecimal(Float.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.floatValue(); }
From source file:Main.java
public static String dropDecimalIfRoundNumber(float val) { if (val == 0) { return "0"; } else if (val % (int) val == 0) { return Integer.toString((int) val); } else {/* www .j ava 2 s.c o m*/ return Float.toString(val); } }
From source file:Main.java
public static Element writeFloatElement(Document document, String name, float value, Element parentElement) { Element element = document.createElement(name); Text text = document.createTextNode(Float.toString(value)); element.appendChild(text);/* w w w . ja va2 s . co m*/ parentElement.appendChild(element); return element; }
From source file:Main.java
public static float roundFloat(Float v, int scale) { if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); }//from ww w.j a va 2 s.c o m BigDecimal b = new BigDecimal(Float.toString(v)); BigDecimal one = new BigDecimal("1"); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).floatValue(); }
From source file:Main.java
private static String justifyOperation(String s, float width, Paint p) { float holder = (float) (COMPLEXITY * Math.random()); while (s.contains(Float.toString(holder))) { holder = (float) (COMPLEXITY * Math.random()); }// ww w . ja v a 2s .c om String holder_string = Float.toString(holder); float lessThan = width; int timeOut = 100; int current = 0; while ((p.measureText(s) < lessThan) && (current < timeOut)) { s = s.replaceFirst(" ([^" + holder_string + "])", " " + holder_string + "$1"); lessThan = (p.measureText(holder_string) + lessThan) - p.measureText(" "); current++; } String cleaned = s.replaceAll(holder_string, " "); return cleaned; }
From source file:Main.java
public static double sub(float v1, float v2) { BigDecimal b1 = new BigDecimal(Float.toString(v1)); BigDecimal b2 = new BigDecimal(Float.toString(v2)); return b1.subtract(b2).doubleValue(); }
From source file:Main.java
public static void addFloatProperty(Document document, Element parent, String name, float value) { addPropertyNode(document, parent, name).setAttribute(FLOAT_ATTR, Float.toString(value)); }
From source file:Main.java
public static void writeFloat(String name, float value, XMLStreamWriter writer) throws XMLStreamException { if (!Float.isNaN(value)) { writer.writeAttribute(name, Float.toString(value)); }//from w w w. ja va 2 s. c om }
From source file:Main.java
private static String dumpRow(Cursor c) { String result = "VALUES("; for (int pos = 0; pos < c.getColumnCount(); pos++) { switch (c.getType(pos)) { case Cursor.FIELD_TYPE_NULL: result += "null"; break; case Cursor.FIELD_TYPE_INTEGER: result += Integer.toString(c.getInt(pos)); break; case Cursor.FIELD_TYPE_FLOAT: result += Float.toString(c.getFloat(pos)); break; case Cursor.FIELD_TYPE_STRING: result += DatabaseUtils.sqlEscapeString(c.getString(pos)); break; case Cursor.FIELD_TYPE_BLOB: result += "X'"; for (byte b : c.getBlob(pos)) { result += String.format("%02X", b); }/*from w w w. ja va 2 s .c o m*/ result += "'"; break; default: return "Invalid field type " + c.getType(pos) + " at position " + pos; } if (pos < c.getColumnCount() - 1) { result += ", "; } } return result + ")"; }