diff --git a/Library/Measure.cpp b/Library/Measure.cpp index c8051662..c914713e 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -510,7 +510,17 @@ const WCHAR* CMeasure::GetStringValue(bool autoScale, double scale, int decimals if(percentual) { - swprintf(buffer, L"%i", (UINT)(100.0 * GetRelativeValue())); + double val = 100.0 * GetRelativeValue(); + + if (decimals == 0) + { + swprintf(buffer, L"%i", (UINT)val); + } + else + { + swprintf(format, L"%%.%if", decimals); + swprintf(buffer, format, val); + } } else if(autoScale) { @@ -518,15 +528,16 @@ const WCHAR* CMeasure::GetStringValue(bool autoScale, double scale, int decimals } else { + double val = GetValue() * (1.0 / scale); + if(decimals == 0) { - double val = GetValue() * (1.0 / scale); val += (val >= 0) ? 0.5 : -0.5; swprintf(buffer, L"%lli", (LONGLONG)val); } else if (decimals == -1) { - swprintf(buffer, L"%.5f", GetValue() * (1.0 / scale)); + swprintf(buffer, L"%.5f", val); size_t len = wcslen(buffer); if (len >= 6 && wcscmp(buffer + len - 6, L".00000") == 0) @@ -537,7 +548,7 @@ const WCHAR* CMeasure::GetStringValue(bool autoScale, double scale, int decimals else { swprintf(format, L"%%.%if", decimals); - swprintf(buffer, format, GetValue() * (1.0 / scale)); + swprintf(buffer, format, val); } } diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 2bfc7d36..7aabf08b 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -272,7 +272,7 @@ void CMeterString::ReadConfig(const WCHAR* section) std::wstring scale; scale = parser.ReadString(section, L"Scale", L"1"); - if (wcschr(scale.c_str(), '.') == NULL) + if (scale.find(L'.') == std::wstring::npos) { m_NoDecimals = true; } @@ -396,8 +396,7 @@ bool CMeterString::Update() { std::vector stringValues; - int decimals = (m_NoDecimals && !m_AutoScale) ? 0 : 1; - if (m_NumOfDecimals != -1) decimals = m_NumOfDecimals; + int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || !m_AutoScale)) ? 0 : 1; if (m_Measure) stringValues.push_back(m_Measure->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual));