From fbbafddd3d41ad94175d906e8ab18c5654080b50 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Wed, 16 Oct 2024 20:48:35 +0200 Subject: [PATCH] fix frequency formatting when copying from frequency selector --- core/src/utils/hrfreq.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/utils/hrfreq.cpp b/core/src/utils/hrfreq.cpp index f61554ca..21b593f3 100644 --- a/core/src/utils/hrfreq.cpp +++ b/core/src/utils/hrfreq.cpp @@ -28,10 +28,14 @@ namespace hrfreq { char numBuf[128]; int numLen = sprintf(numBuf, "%0.*lf", maxDecimals, freq); - // Remove the useless zeros - for (int i = numLen-1; i >= 0; i--) { - if (numBuf[i] != '0' && numBuf[i] != '.') { break; } - numBuf[i] = 0; + // If there is a decimal point, remove the useless zeros + if (maxDecimals) { + for (int i = numLen-1; i >= 0; i--) { + bool dot = (numBuf[i] == '.'); + if (numBuf[i] != '0' && !dot) { break; } + numBuf[i] = 0; + if (dot) { break; } + } } // Concat the suffix