Merge pull request 'Mow Units: No rounding' (#3) from kdmukai/btclock_v3:mow_units_no_rounding into main
Reviewed-on: #3
This commit is contained in:
commit
3b6f1db3c5
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;
|
std::string priceString;
|
||||||
if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat)
|
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);
|
priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode);
|
||||||
}
|
}
|
||||||
else
|
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(), ' ');
|
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
|
||||||
|
|
||||||
|
if (mowMode)
|
||||||
|
{
|
||||||
|
ret[0] = "MOW/UNITS";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
|
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
firstIndex = 1;
|
firstIndex = 1;
|
||||||
|
|
|
@ -83,15 +83,32 @@ std::string formatNumberWithSuffix(std::uint64_t num, int numCharacters, bool mo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add suffix
|
// 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 there's room, add more decimal places
|
||||||
if (len < numCharacters)
|
if (len < numCharacters)
|
||||||
{
|
{
|
||||||
int restLen = mowMode ? numCharacters - len : numCharacters - len - 1;
|
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);
|
snprintf(result, sizeof(result), "%.*f%c", restLen, numDouble, suffix);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue