How to display "03.141" with lv_label_set_text_fmt?

Description

What MCU/Processor/Board and compiler are you using?

KEIL5.39,STM32F407,LVGL8.4

What do you want to achieve?

lv_label_set_text_fmt(scr_ui->screen_num_disp_label_disp_v,“%05.3f”,(float)3.141);
03.141 is displayed.

What have you tried so far?

/Change the built in (v)snprintf functions/
#define LV_SPRINTF_CUSTOM 1
#if LV_SPRINTF_CUSTOM
#define LV_SPRINTF_INCLUDE <stdio.h>
#define lv_snprintf snprintf
#define lv_vsnprintf vsnprintf
#else /LV_SPRINTF_CUSTOM/
#define LV_SPRINTF_USE_FLOAT 1
#endif /LV_SPRINTF_CUSTOM/

Code to reproduce

lv_label_set_text_fmt(scr_ui->screen_num_disp_label_disp_v,"%05.3f",(float)3.141);

Screenshot and/or video

Currently, 3.141 is displayed.

3.141 is ok for 05.3f
use 06.3 or 05.2 …

1 Like

I need to show “03.141”, but now it shows “3.141”.

Hey, you already tried using %06.3f?

like this:

lv_label_set_text_fmt(scr_ui->screen_num_disp_label_disp_v,"%06.3f",(float)3.141);
1 Like

I saw what you said and tried it, it is indeed the effect I want (03.141); I was careless. Thank you for reminding me to solve the problem.

1 Like