Errrr, nevermind. I forgot I had added the period in when I did the test for length to add the leading zero and blank space. Here’s what I hope is the real fix.
String TimeConvert(long time)
{
// takes the time as argument and returns the time for that hit as a XX.xxs string
if (time != 0) // Make sure there's a value...
{
String tmp3 = String(int((time + 5)/10)); // round msecs into csecs
int k = tmp3.length(); // k will be index to last char in padded string
int km1 = k-1; // km1 will be index to next to last char
int km2 = k-2; // km2 will be position of period
tmp3 = tmp3 + '0'; // pad the end of the truncated string with a zero
//now move chars to make space to add a period
tmp3.setCharAt(k, tmp3.charAt(km1)); // move next-2-last to last position in string
tmp3.setCharAt(km1, tmp3.charAt(km2)); // move char to next-2-last position
// now insert period
tmp3.setCharAt(km2, '.');
// add a blank or 2 as needed to get 5 digits with time right justified
if(tmp3.length() < 4)
{
tmp3 = " 0" + tmp3; // must be a sub 1 sec time add a blank and a leading 0
}
else
{
if (tmp3.length() < 5)
{
tmp3 = ' ' + tmp3; // must be a sub 10 sec time add a blank to justify
}
{
// tmp3 now holds rounded time in secs XX.xx format
tmp3 += 's': // add s for seconds
return tmp3;
}
else
{
String tmp3 = " "; // If the time variable is zero pass 6 blanks back as a string...
return tmp3;
}
}
What were you saying about drunk college students writing crap code … :oops: