kima2/src/core/utils.cpp

31 lines
841 B
C++
Raw Normal View History

#include "utils.h"
#include <iomanip>
#include <numeric>
2018-08-09 08:31:38 +02:00
#include <codecvt>
std::string formatCentAsEuroString(const int cent, int width)
{
std::stringstream currStream;
try {
std::locale myLocale("de_DE.utf8");
currStream.imbue(myLocale);
currStream << std::right << std::setw(width) << std::showbase
<< std::put_money(cent, false);
} catch (std::runtime_error& err) {
2018-08-08 15:55:35 +02:00
currStream << std::fixed << std::setw(width >= 4 ? width - 4 : width)
<< std::setprecision(2) << cent / 100.0L << "";
}
return currStream.str();
2018-08-08 09:25:37 +02:00
}
2018-08-08 15:55:35 +02:00
#ifdef _WIN32
2018-08-09 08:31:38 +02:00
std::string convertFromUtf16ToUtf8(std::u16string& utf16String)
2018-08-08 15:55:35 +02:00
{
2018-08-09 08:31:38 +02:00
std::string u8_conv = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(utf16String);
return u8_conv;
2018-08-08 15:55:35 +02:00
}
2018-08-09 08:31:38 +02:00
#endif