Mike sent me a display format for displaying time and date on the screen.
It was sprintf(charBuff, "%0d", numbertoconvert);
Now I need to convert a floating point number to a displayable format.
I've tried a number of variations of
sprintf(charBuff, "%xxf", floatingpointnumber);
where xx is 0, 1, 0.1, 1.1, 2, etc.
All I seem able to display is ?
I assume that the ? means that the format can't be converted.
my floating point numbers are x.x and xx.x
Sounds pretty simple.
A Wikipedia search on sprint hasn't gotten me any help.
Any ideas?
Display formatting for RA8875
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- pkourany
- Posts: 51
- Joined: Wed Nov 27, 2013 12:57 pm
Re: Display formatting for RA8875
bradv, the best reference for sprintf is printf! This a good reference: http://www.cplusplus.com/reference/cstdio/printf/
In your case, you would want to use sprintf(charBuff, "%4.1f", floatingpointnumber);
The 4 specifies the minimum number of digits to print (smaller numbers are padded with spaces)
The 1 specifies the number of digits to print on the right of the decimal point
Hopefully, that works for you :)
In your case, you would want to use sprintf(charBuff, "%4.1f", floatingpointnumber);
The 4 specifies the minimum number of digits to print (smaller numbers are padded with spaces)
The 1 specifies the number of digits to print on the right of the decimal point
Hopefully, that works for you :)
- bradv
- Posts: 35
- Joined: Sat Feb 22, 2014 2:38 am
Re: Display formatting for RA8875
Tried your suggestion.
I stubbed out most of the code to isolate this section and keep getting the same answer.
The function prints CharBuff to the screen correctly.
CharBuff actually contains a '?'.
Here's the snippet.
PHnow is defined as "float PHnow".
Great reference.
Thanks.
I stubbed out most of the code to isolate this section and keep getting the same answer.
The function prints CharBuff to the screen correctly.
CharBuff actually contains a '?'.
Here's the snippet.
Code: Select all
PHnow = 5.4;
if (PHnow < (PHSet[ZonePtr] + 0.2) && PHnow > (PHSet[ZonePtr] - 0.2))
{
tft.fillRect(620, 140, 120, 50, RA8875_CYAN); // draw PH Box
tft.textTransparent (RA8875_BLACK);
tft.textSetCursor (645,140);
sprintf(CharBuff,
"%4.1f", PHnow);
tft.textWrite (CharBuff);
}
else
{
tft.fillRect(620, 140, 120, 50, RA8875_RED); // PH Box
tft.textTransparent (RA8875_WHITE);
tft.textSetCursor (645,140);
sprintf(CharBuff,
"%4.1f", PHnow);
tft.textWrite (CharBuff);
}
Great reference.
Thanks.
Please be positive and constructive with your questions and comments.