Greetings Kind Regards
I am attempting to duplicate in C++ the work shown on Code Project article titled "International Number Formats" link below. My C++ code is shown below and output also. Each line of output is the number 123.56 in my global locale then the language-nation string then the number per the locale. Please note not all outputs are correct as stated at end of each line.
Thank You Kindly
International Number Formats[
^]
1234.56 en-US 1,234.56 ok
1234.56 da-DK 1.234,56 ok
1234.56 it-CH 1Æ234.56 expected 1'234.56
1234.56 fi-FI 1á234,56 expected 1 234,56
1234.56 fa-IR 1,234/56 ok
1234.56 kk-KZ 1┬234,56 expected 1 234-56
1234.56 et-EE 1á234,56 expected 1 234.56
#include <iostream>
#include <locale>
#include <sstream>
using namespace std;
char narrow_space = ' ';
char wide_space = L' ';
#define LINE_FUNCSIG cout << __LINE__ << narrow_space << __FUNCSIG__<<endl;
template<typename charType, typename numberType> requires is_arithmetic_v<numberType>
basic_string<charType> formatted_number(numberType _number, const string& _std_name)
{
basic_ostringstream<charType> _ostream;
_ostream.imbue(locale(_std_name));
_ostream << _number;
cout << _number << narrow_space << _std_name << narrow_space << _ostream.str() << endl;
return _ostream.str();
}
int main()
{
cout << "Hello World !\n" << boolalpha;
wcout << L"Again Hello World !\n" << boolalpha << endl;
auto _number = 1234.56;
formatted_number<char>(_number, "en-US");
formatted_number<char>(_number, "da-DK");
formatted_number<char>(_number, "it-CH");
formatted_number<char>(_number, "fi-FI");
formatted_number<char>(_number, "fa-IR");
formatted_number<char>(_number, "kk-KZ");
formatted_number<char>(_number, "et-EE");
return 0;
}
What I have tried:
searched web, examined cppreference.com, inquired ChatGBT, examined "Related Entries"