private char fmt; // one of cdeEfgGiosxXos
+ private final String formatString;
+
/**
* Creates a new Format object.
*
*/
public Format(String s)
{
+ formatString = s;
width = 0;
precision = -1;
pre = "";
/**
* Formats a character into a string (like sprintf in C)
*
- * @param x
+ * @param debounceTrap
* the value to format
* @return the formatted string
*/
/**
* Formats a string into a larger string (like sprintf in C)
*
- * @param x
+ * @param debounceTrap
* the value to format
* @return the formatted string
*/
return f + p.substring(p.length() - 3, p.length());
}
+
+ @Override
+ public String toString()
+ {
+ return formatString;
+ }
+
+ /**
+ * Bespoke method to format percentage float value to the specified number of
+ * decimal places. Avoids use of general-purpose format parsers as a
+ * processing hotspot.
+ *
+ * @param sb
+ * @param value
+ * @param dp
+ */
+ public static void appendPercentage(StringBuilder sb, float value, int dp)
+ {
+ sb.append((int) value);
+ if (dp > 0)
+ {
+ sb.append(".");
+ while (dp > 0)
+ {
+ value = value - (int) value;
+ value *= 10;
+ sb.append((int) value);
+ dp--;
+ }
+ }
+ }
}