From 726594b926d3e8b7f131e9b611179a68d338f65c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 31 Oct 2024 17:08:07 +0800 Subject: [PATCH] fix: float display issue --- include/common/ttypes.h | 4 ++-- source/libs/scalar/src/sclfunc.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 087e593195..bf9205ecfe 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -241,14 +241,14 @@ typedef struct { case TSDB_DATA_TYPE_FLOAT: { \ int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (int32_t)((_outputBytes) - 1), *(float *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \ } \ break; \ } \ case TSDB_DATA_TYPE_DOUBLE: { \ int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ if (n >= (_outputBytes)) { \ - snprintf(_output, (int32_t)(_outputBytes), "%*.7f", (int32_t)((_outputBytes) - 1), *(double *)(_input)); \ + snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \ } \ break; \ } \ diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 6f6362a8f7..d01a5ed7ab 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2085,7 +2085,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp (void)memcpy(varDataVal(output), convBuf, len); varDataSetLen(output, len); } else { - NUM_TO_STRING(inputType, input, bufSize, buf); + int32_t outputSize = TMIN(outputLen - VARSTR_HEADER_SIZE, bufSize); + NUM_TO_STRING(inputType, input, outputSize, buf); int32_t len = (int32_t)strlen(buf); len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE); (void)memcpy(varDataVal(output), buf, len);