Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C++
#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();
}

// https://www.codeproject.com/articles/78175/international-number-formats

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"
Posted
Updated 17-Apr-24 4:09am
v2

1 solution

You already posted this in the C/C++ forum. Don't spam the site with the same question in multiple places.
 
Share this answer
 
Comments
BernardIE5317 17-Apr-24 15:42pm    
I thought I hit the [Cancel] button. Thank you for your due diligence.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900