1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

lv_math: lv_math_num_to_str: return with buf

This commit is contained in:
Gabor Kiss-Vamosi 2018-03-07 13:10:20 +01:00
parent 19f98ce8ea
commit 13351c0091
2 changed files with 12 additions and 3 deletions

View File

@ -37,14 +37,15 @@
* Convert a number to string * Convert a number to string
* @param num a number * @param num a number
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
* @return same as `buf` (just for convenience)
*/ */
void lv_math_num_to_str(int32_t num, char * buf) char * lv_math_num_to_str(int32_t num, char * buf)
{ {
char * buf_ori = buf; char * buf_ori = buf;
if(num == 0) { if(num == 0) {
buf[0] = '0'; buf[0] = '0';
buf[1] = '\0'; buf[1] = '\0';
return; return buf;
} else if(num < 0) { } else if(num < 0) {
(*buf) = '-'; (*buf) = '-';
buf++; buf++;
@ -85,6 +86,8 @@ void lv_math_num_to_str(int32_t num, char * buf)
} }
(*buf) = '\0'; (*buf) = '\0';
return buf_ori;
} }
/********************** /**********************

View File

@ -31,7 +31,13 @@ extern "C" {
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
void lv_math_num_to_str(int32_t num, char * buf); /**
* Convert a number to string
* @param num a number
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
* @return same as `buf` (just for convenience)
*/
char * lv_math_num_to_str(int32_t num, char * buf);
/********************** /**********************
* MACROS * MACROS