Removed trailing zeros when DynamicVariables=1 even if a value is such as "1.01000".

E.g.
 1.00000 -> 1
 1.01000 -> 1.01
 1.01001 -> 1.01001
This commit is contained in:
spx 2011-07-02 10:16:38 +00:00
parent 8ae8a68547
commit 341e9d2bd0
3 changed files with 25 additions and 8 deletions

View File

@ -569,13 +569,8 @@ const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int dec
}
else if (decimals == -1)
{
_snwprintf_s(buffer, _TRUNCATE, L"%.5f", val);
size_t len = wcslen(buffer);
if (len >= 6 && wcscmp(&buffer[len - 6], L".00000") == 0)
{
buffer[len - 6] = L'\0';
}
int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", val);
RemoveTrailingZero(buffer, len);
}
else
{
@ -631,6 +626,26 @@ void CMeasure::GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue
_snwprintf_s(buffer, sizeInWords, _TRUNCATE, format, value);
}
void CMeasure::RemoveTrailingZero(WCHAR* str, int strLen)
{
--strLen;
while (strLen >= 0)
{
if (str[strLen] == L'0')
{
str[strLen] = L'\0';
--strLen;
}
else
{
if (str[strLen] == L'.')
{
str[strLen] = L'\0';
}
break;
}
}
}
/*
** GetStats

View File

@ -78,6 +78,7 @@ public:
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords);
static void RemoveTrailingZero(WCHAR* str, int strLen);
static CMeasure* Create(const WCHAR* measure, CMeterWindow* meterWindow, const WCHAR* name);

View File

@ -983,7 +983,8 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
if (result != -1)
{
WCHAR buffer[256];
_snwprintf_s(buffer, _TRUNCATE, L"%f", value);
int len = _snwprintf_s(buffer, _TRUNCATE, L"%.5f", value);
CMeasure::RemoveTrailingZero(buffer, len);
const std::wstring& resultString = buffer;