I can print out on the LCD the value of _splitdiff, eg +9999, -1234, +1234 etc
What I would like to be able to do is to display the value in the format +00.00 eg +99.99, -12.34, +12.34 etc
In the existing code a series of str[0] = str[1]; type commands after the sprintf command seem to format the printed value i.e. add "," and "." . I cant seem to find out how this is done.......example is below:
How about creating a new variable called str_formatted(?) in order to "format" it?
The last lines of the last code you passed format the string in order to include the "." and the ",", assigning this values in positions of the string (str[n] where n=position).
If you want to do it, just be sure how many positions of the str are being used in order to not assigning values to positions you will have to use. For example:
str = 9999, and you want to show as 99.99.
You can use:
str_formatted[0] = str[0];
str_formatted[1] = str[1];
str_formatted[2] = '.';
str_formatted[3] = str[2];
str_formatted[4] = str[3];
g4edg:
What I would like to be able to do is to display the value in the format +00.00 eg +99.99, -12.34, +12.34 etc
Separate the number into two parts using div and mod operators, then print those separately into the string:
char buf[32]; // make it however big you need;
int count = 1234; // your input value
int hundreds = value/100; // hundreds contains 12
int units = value % 100; // units contains 34
snprintf(buf, sizeof(buf) "%02d:%02d", hundreds, units);
// buf now contains "12:34"