From 132aa835cd8492900b9af9bc89f6cd1e25ad4635 Mon Sep 17 00:00:00 2001 From: kdmukai Date: Mon, 9 Dec 2024 15:58:39 -0600 Subject: [PATCH 1/2] Mow Units no rounding! --- lib/btclock/data_handler.cpp | 11 +++++++++-- lib/btclock/utils.cpp | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/btclock/data_handler.cpp b/lib/btclock/data_handler.cpp index b489bb8..eaf4538 100644 --- a/lib/btclock/data_handler.cpp +++ b/lib/btclock/data_handler.cpp @@ -73,7 +73,7 @@ std::array parsePriceData(std::uint32_t price, char cu std::string priceString; if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat) { - int numScreens = shareDot && !mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2; + int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2; priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode); } else @@ -85,7 +85,14 @@ std::array parsePriceData(std::uint32_t price, char cu { priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); - ret[0] = "BTC/" + getCurrencyCode(currencySymbol); + if (mowMode) + { + ret[0] = "MOW/UNITS"; + } + else + { + ret[0] = "BTC/" + getCurrencyCode(currencySymbol); + } firstIndex = 1; diff --git a/lib/btclock/utils.cpp b/lib/btclock/utils.cpp index 9056d14..45dfdd2 100644 --- a/lib/btclock/utils.cpp +++ b/lib/btclock/utils.cpp @@ -1,4 +1,5 @@ #include "utils.hpp" +#include int modulo(int x, int N) { @@ -83,14 +84,31 @@ std::string formatNumberWithSuffix(std::uint64_t num, int numCharacters, bool mo } // Add suffix - int len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix); + int len; + + // Mow Mode always uses string truncation to avoid rounding + std::string mowAsString = std::to_string(numDouble); + if (mowMode) { + // Default to one decimal place + len = snprintf(result, sizeof(result), "%s%c", mowAsString.substr(0, mowAsString.find(".") + 2).c_str(), suffix); + } + else + { + len = snprintf(result, sizeof(result), "%.0f%c", numDouble, suffix); + } // If there's room, add more decimal places if (len < numCharacters) { int restLen = mowMode ? numCharacters - len : numCharacters - len - 1; - - snprintf(result, sizeof(result), "%.*f%c", restLen, numDouble, suffix); + + if (mowMode) { + snprintf(result, sizeof(result), "%s%c", mowAsString.substr(0, mowAsString.find(".") + 2 + restLen).c_str(), suffix); + } + else + { + snprintf(result, sizeof(result), "%.*f%c", restLen, numDouble, suffix); + } } return result; From 9ada991ab15f7aa90060c8692da8554852617d7b Mon Sep 17 00:00:00 2001 From: kdmukai Date: Mon, 9 Dec 2024 16:05:55 -0600 Subject: [PATCH 2/2] Update utils.cpp --- lib/btclock/utils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/btclock/utils.cpp b/lib/btclock/utils.cpp index 45dfdd2..0e19962 100644 --- a/lib/btclock/utils.cpp +++ b/lib/btclock/utils.cpp @@ -1,5 +1,4 @@ #include "utils.hpp" -#include int modulo(int x, int N) {