I have a floating point number and want to round it to 1 decimal place and also want to display the .0 if it ends up a whole number. I then want to make this into a string to use in another function to display it on my LCD.
So far I have this:
This gives me the hundreds, tens and units and the decimal place numbers into char1, char2, char3 and afterDP.
To get the ASCII values, I will add 0x30 to each character.
I already have a function I can call to display a string to my screen, the function is:
I can call it by:
But what I want to do is be able to call the function with a string that is made up of the characters; char1, char2, char3, a decimal point, afterDP
How do I go about this?
Oh, I am using XC8 compiler for a PIC
So far I have this:
Rich (BB code):
uint16 wholeNumber = trunc(val); // truncate the value to get the whole number
uint16 afterDP = round((val*10) - (wholeNumber*10)); // get 1 DP by rounding (val*10 - wholeNumber*10)
uint8 char1 = wholeNumber/100;
uint8 char2 = (wholeNumber - (char1*100))/10;
uint8 char3 = wholeNumber-(char1*100)-(char2*10);
To get the ASCII values, I will add 0x30 to each character.
I already have a function I can call to display a string to my screen, the function is:
Rich (BB code):
void displaySmallString(uint8 x, uint8 y, char *characters);
Rich (BB code):
displaySmallString(10,10, "Hello");
How do I go about this?
Oh, I am using XC8 compiler for a PIC