cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx: I am displaying a double in a Text area but cannot get more than 6 decimal places

Garnett.Robert
Senior III

Hi,

I am using a text area to display a precision timer output (double) and need 8 decimal places of precision. Thye best I can get is six:

I have a wildcard buffer of twenty and the following code:

/* Backend code */
 
typedef struct
{
 
		volatile uint32_t timerCountUpperWord;
		volatile uint64_t clockTimerT1;
		uint64_t 	clockBeatCount;
		uint8_t		clockTenBeatCounter;
		uint16_t	clockTenMinuteCounter;
		uint32_t	clockFourHourCounter;
		uint64_t 	tenTickStartTime;
		uint16_t	tenMinuteBeatCount;
		uint32_t	fourHourBeatCount;
		double 		tenTickBPM;
		uint64_t 	tenMinuteStartTime;
		double 		tenMinuteBPM;
		uint64_t 	fourHourStartTime;
		double	 	fourHourBPM;
 
		uint8_t		tenTicksComplete;
		uint8_t 	tenMinutesComplete;
		uint8_t   fourHoursComplete;
 
		uint8_t 	resetBPMFlag;
		uint8_t 	runFlag;
		uint8_t 	runInitFlag;
 
		uint8_t 	progInd10Ticks;
		uint8_t	progInd10Minutes;
		uint8_t	progInd4Hours;
}timerData_t;
  
timerData_t tData;
 
/*Touchgfx Code */ 
Unicode::snprintfFloat(textBPM_10TicksBuffer, TEXTBPM_10TICKS_SIZE, "%03.8f", tData.tenTickBPM);

The best I get is 90.056274 which is six decimal places.

If I change the code to:

Unicode::snprintfFloat(textBPM_10TicksBuffer, TEXTBPM_10TICKS_SIZE, "%03.12f", tData.tenTickBPM);

I get the same precision:

89.988746.

Which is 6 decimal places.

What am I doing wrong?

4 REPLIES 4
Peter BENSCH
ST Employee

What is the value of TEXTBPM_10TICKS_SIZE?

Sorry, missed you mentioned the 20 characters above.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Peter,

The size of the buffer was the first thing I thought of that's why I made it larger than I needed at 20.

Love the Touchgfx package. It took me about two days to get to grips with the basics. Once you get the hang of it Touchgfx is great easy to use, powerful and it produces great looking interfaces.

Before TGFX i used mobile phones with Blutooth or WiFi and custom apps for a decent interface, with Touchgfx that's no longer necessary. Using custom phone apps is a pain as you have to do Android and Apple. I used B4x for this as it is excellent for people who don't want to program in Java. Where I still need a phone app I will continue to use B4x.

Congratulations go to ST and Draupner Graphics for making such an excellent package available to everyone.

I will publish the project I'm working on at the moment at it may be useful to others starting up with Touchgfx.

Best regards

Rob

Piranha
Chief II
"%03.12f"

The number preceding the dot ("3" in this case) is not a number of digits before the decimal separator. It's a minimum number of total characters (not digits!) printed for the particular field.

https://en.cppreference.com/w/c/io/fprintf

Yes,

I know that is what it is supposed to be as per the documentation:

https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_unicode/#snprintffloat

Viz:

\%[flags][width][.precision]f

If I write

\%[flags][width][.precision]f
"%011.8f"

0089.988723

If I try:

"%013.8f"

I get:

000089.988723

The floating point number being displayed is: 89.98872391054008 using STM32CubeIDE Live Watch variable.

It simply does not work like the normal C /C++ printf or the Touchgfx snprintfloat documentation.

I have checked the layout an I am not truncating it in the display.

0693W000008yM76QAE.jpgIn this case the reading was 90.943244

The textArea extends out to the yellow border near the wren's tail so there is plenty of room for more another two digits.