diff options
author | George Hazan <ghazan@miranda.im> | 2020-11-04 21:17:18 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-11-04 21:17:18 +0300 |
commit | 55cf177a159aca7c4727a5d23901d33735939a29 (patch) | |
tree | 0c7b0fc566f791843ab263b2c2b8b7f9342fdb21 | |
parent | bf8ab82826fd61cb64f4913322f1b6bf584a86f8 (diff) |
fixes #2607 (CurrencyRates incorrect displays Bitcoin rate)
-rw-r--r-- | protocols/CurrencyRates/src/Chart.h | 7 | ||||
-rw-r--r-- | protocols/CurrencyRates/src/CurrencyConverter.cpp | 27 | ||||
-rw-r--r-- | protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp | 22 | ||||
-rw-r--r-- | protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp | 14 | ||||
-rw-r--r-- | protocols/CurrencyRates/src/version.h | 2 |
5 files changed, 24 insertions, 48 deletions
diff --git a/protocols/CurrencyRates/src/Chart.h b/protocols/CurrencyRates/src/Chart.h index 1247ead065..430d067781 100644 --- a/protocols/CurrencyRates/src/Chart.h +++ b/protocols/CurrencyRates/src/Chart.h @@ -27,10 +27,9 @@ namespace detail static tstring ToString(double v) { - tostringstream s; - s.imbue(std::locale("")); - s << std::fixed << v; - return s.str(); + wchar_t str[40]; + swprintf_s(str, L"%.6lf", v); + return str; } }; } diff --git a/protocols/CurrencyRates/src/CurrencyConverter.cpp b/protocols/CurrencyRates/src/CurrencyConverter.cpp index 67c2b80e4f..f1af844080 100644 --- a/protocols/CurrencyRates/src/CurrencyConverter.cpp +++ b/protocols/CurrencyRates/src/CurrencyConverter.cpp @@ -60,10 +60,9 @@ inline void update_swap_button(HWND hDlg) inline tstring double2str(double dValue) { - tostringstream output; - output.imbue(GetSystemLocale()); - output << std::fixed << std::setprecision(2) << dValue; - return output.str(); + wchar_t str[40]; + swprintf_s(str, L"%.2lf", dValue); + return str; } inline bool str2double(const tstring& s, double& d) @@ -201,23 +200,9 @@ INT_PTR CALLBACK CurrencyConverterDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM const auto pProvider = get_currency_converter_provider(); assert(pProvider); if (pProvider) { - tstring sResult; - std::string sError; - try { - double dResult = pProvider->Convert(dAmount, from, to); - tostringstream ss; - ss.imbue(GetSystemLocale()); - ss << std::fixed << std::setprecision(2) << dAmount << " " << from.GetName() << " = " << dResult << " " << to.GetName(); - sResult = ss.str(); - } - catch (std::exception& e) { - sError = e.what(); - } - - if (false == sError.empty()) - sResult = currencyrates_a2t(sError.c_str());//A2T(sError.c_str()); - - SetDlgItemText(hDlg, IDC_EDIT_RESULT, sResult.c_str()); + double dResult = pProvider->Convert(dAmount, from, to); + CMStringW sResult(FORMAT, L"%.2lf %s = %.2lf %s", dAmount, from.GetName().c_str(), dResult, to.GetName().c_str()); + SetDlgItemText(hDlg, IDC_EDIT_RESULT, sResult); } } } diff --git a/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp b/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp index a6259b79cc..b9feaf046b 100644 --- a/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp +++ b/protocols/CurrencyRates/src/CurrencyRateInfoDlg.cpp @@ -37,31 +37,27 @@ INT_PTR CALLBACK CurrencyRateInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT TranslateDialogDefault(hdlg); { tstring sDescription = GetContactName(hContact); - ::SetDlgItemText(hdlg, IDC_STATIC_CURRENCYRATE_NAME, sDescription.c_str()); + ::SetDlgItemTextW(hdlg, IDC_STATIC_CURRENCYRATE_NAME, sDescription.c_str()); double dRate = 0.0; if (true == CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_PREV_VALUE, dRate)) { - tostringstream o; - o.imbue(GetSystemLocale()); - o << dRate; - - ::SetDlgItemText(hdlg, IDC_EDIT_PREVIOUS_RATE, o.str().c_str()); + wchar_t str[40]; + swprintf_s(str, L"%.6lf", dRate); + ::SetDlgItemTextW(hdlg, IDC_EDIT_PREVIOUS_RATE, str); } dRate = 0.0; if (true == CurrencyRates_DBReadDouble(hContact, MODULENAME, DB_STR_CURRENCYRATE_CURR_VALUE, dRate)) { - tostringstream o; - o.imbue(GetSystemLocale()); - o << dRate; - - ::SetDlgItemText(hdlg, IDC_EDIT_RATE, o.str().c_str()); + wchar_t str[40]; + swprintf_s(str, L"%.6lf", dRate); + ::SetDlgItemTextW(hdlg, IDC_EDIT_RATE, str); } time_t nFetchTime; if (true == get_fetch_time(nFetchTime, hContact)) { wchar_t szTime[50] = { 0 }; if (0 == _tctime_s(szTime, 50, &nFetchTime)) { - ::SetDlgItemText(hdlg, IDC_EDIT_RATE_FETCH_TIME, szTime); + ::SetDlgItemTextW(hdlg, IDC_EDIT_RATE_FETCH_TIME, szTime); } } @@ -69,7 +65,7 @@ INT_PTR CALLBACK CurrencyRateInfoDlgProcImpl(MCONTACT hContact, HWND hdlg, UINT tostringstream o; o << TranslateT("Info provided by") << L" <a href=\"" << pi.m_sURL << L"\">" << pi.m_sName << L"</a>"; - ::SetDlgItemText(hdlg, IDC_SYSLINK_PROVIDER, o.str().c_str()); + ::SetDlgItemTextW(hdlg, IDC_SYSLINK_PROVIDER, o.str().c_str()); } return TRUE; diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp index a0df4d5893..5afc061877 100644 --- a/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp +++ b/protocols/CurrencyRates/src/CurrencyRatesProviderBase.cpp @@ -354,7 +354,7 @@ tstring format_rate(const ICurrencyRatesProvider *pProvider, MCONTACT hContact, case 't': sResult += L"\t"; break; case 'n': sResult += L"\n"; break; case '\\': sResult += L"\\"; break; - default: sResult += chr; sResult += t; break; + default: sResult += chr; sResult += t; break; } ++i; } @@ -862,15 +862,11 @@ static tstring format_fetch_time(MCONTACT hContact, const tstring &rsFormat) static tstring format_double(double dValue, int nWidth) { - tostringstream o; - o.imbue(GetSystemLocale()); - + wchar_t str[100], format[] = L"%.6lf"; if (nWidth > 0 && nWidth <= 9) - o << std::setprecision(nWidth) << std::showpoint << std::fixed; - - o << dValue; - - return o.str(); + format[2] = '0' + nWidth; + swprintf_s(str, format, dValue); + return str; } tstring CCurrencyRatesProviderBase::FormatSymbol(MCONTACT hContact, wchar_t c, int nWidth) const diff --git a/protocols/CurrencyRates/src/version.h b/protocols/CurrencyRates/src/version.h index cc953af4dc..764539f356 100644 --- a/protocols/CurrencyRates/src/version.h +++ b/protocols/CurrencyRates/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 2 #define __RELEASE_NUM 1 -#define __BUILD_NUM 0 +#define __BUILD_NUM 1 #include <stdver.h> |