Mow Units: No rounding #3
2 changed files with 29 additions and 5 deletions
|
@ -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(), ' ');
|
||||
|
||||
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
|
||||
if (mowMode)
|
||||
{
|
||||
ret[0] = "MOW/UNITS";
|
||||
}
|
||||
else
|
||||
{
|
||||
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
|
||||
}
|
||||
|
||||
|
||||
firstIndex = 1;
|
||||
|
|
|
@ -83,14 +83,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;
|
||||
|
|
Loading…
Reference in a new issue