While searching for efficient gesture detection code, I stumbled upon a function that converts decimal numbers to char arrays in an example program written by Google. It serves my needs perfectly.
The original code can be found here: http://developer.android.com/training/gestures/index.html (Click "try it out" on the right to download the zip containing the project)
I've copied the relevant function here, just in case.
private static final int POW10[] = {1, 10, 100, 1000, 10000, 100000, 1000000};
/**
* Formats a float value to the given number of decimals. Returns the length of the string.
* The string begins at out.length - [return value].
*/
private static int formatFloat(final char[] out, float val, int digits) {
boolean negative = false;
if (val == 0) {
out[out.length - 1] = '0';
return 1;
}
if (val < 0) {
negative = true;
val = -val;
}
if (digits > POW10.length) {
digits = POW10.length - 1;
}
val *= POW10[digits];
long lval = Math.round(val);
int index = out.length - 1;
int charCount = 0;
while (lval != 0 || charCount < (digits + 1)) {
int digit = (int) (lval % 10);
lval = lval / 10;
out[index--] = (char) (digit + '0');
charCount++;
if (charCount == digits) {
out[index--] = '.';
charCount++;
}
}
if (negative) {
out[index--] = '-';
charCount++;
}
return charCount;
}