I need some code that will convert a 4 digit float
72.30 is a 5 character string, and is not at all representative of how the value is stored internally.
You could, however, add 0.005 to the float value, multiply by 100 and store in an int. So, 72.30 becomes 72.305 which becomes 7230.5 which becomes 7230. The addition of the 0.005 is necessary for proper rounding, so 72.306 becomes 7231, not 7230.
Then, with the modulo function, you can extract the 4 numbers individually, or use itoa() or sprintf() to convert the int to a string, and then convert the individual characters in the array to numbers.
int val = 7230;
char array[5];
sprintf(array, "%i", val);
int value1 = array[0] - '0'; // value1 <-- '7' - '0' = 7
int value2 = array[1] - '0'; // <-- 2
int value3 = array[2] - '0'; // <-- 3
int value4 = array[3] - '0'; // <-- 0
Say I want two digits after decimal and all digits before decimal, from a float called number:
int int_number=number*100.0; // Two digits after decimal are kept. Turn the number into integer
char digits[10];//Just in case I have 8 digits before decimal
for (byte i=0;i<10;i++)
{
digits[i]=int_number%10;
if (int_number==0) break;
int_number/=10;
}
If you want characters instead, do digits*='0'+int_number%10;* Should work