Decimals on TFT

OK, final post on this thread...

I have tweaked the dec2str() function and renamed dec2strf(), available here in an example sketch.

dec2strf(floatValue, precision);

returns a pointer to a string with "precision" digits after the decimal point. precision is deliberately limited to 7 maximum.

ILI9341 TFT users may be interested to know that the function has been built into the TFT_ILI9341 graphics library as drawFloat(value, precision, x, y , font). A typical use is to display parameters (temperature voltage etc) on the TFT.

Usual caveats apply as I am a R&R software writer :wink:

rowboteer:
The mead was stronger than I thought :slight_smile:

Mead isn't for coding; Caf-Pow is for coding.
Mead is for testing.

I decided to poke around in the Arduino IDE directory to see if I could find the function that print uses, it was easy to find at the very end of the Print.cpp file buried here:

C:...\arduino-1.6.5-r2\hardware\arduino\avr\cores\arduino

a few extra checks are included like "not a number" and divide by zero (viz. infinity) but the function otherwise uses the same approach as I ended up using in the dec2strf function.

use sprintf function. It is the best way you can get your data.

example:
int int_year = 15;
char year[5];

sprintf(year, "%04d", int_year);

RESULT=> 0015 in variable of year and you can edit it:
year[0] = '2';
year[1] = '0';

RESULT=> "2015" in year variable.

You can use it to get any character from you data and change it again to any type of variable you need it. :wink:

hasanvaez:
use sprintf function. It is the best way you can get your data.

Printing to 2 decimal places was requested in this thread... whoops!