Mow Units no rounding!

This commit is contained in:
kdmukai 2024-12-09 15:58:39 -06:00
parent d6604d28d6
commit 132aa835cd
2 changed files with 30 additions and 5 deletions

View file

@ -73,7 +73,7 @@ std::array<std::string, NUM_SCREENS> 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<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char cu
{
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
if (mowMode)
{
ret[0] = "MOW/UNITS";
}
else
{
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
}
firstIndex = 1;

View file

@ -1,4 +1,5 @@
#include "utils.hpp"
#include <iostream>
int modulo(int x, int N)
{
@ -83,15 +84,32 @@ 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;
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;
}