473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

locale and numeric output

Hi!

My problem looks like this:

#include <iostream>
#include <locale>

int main(int argc, char* argv[])
{
std::locale::global( std::locale( "deu" ) );
std::cout.imbue( std::locale() );
std::cout << 1000.4 << " " << 0.4 << std::endl;
return 0;
}

This is MS VC++ 7.1 here (explains the "deu" locale, it's the same with
"german").

Output is:

1,000.4 0,4

Now, this is confusing! I really expected

1.000,4 0,4

Any suggestions?

Regards,
M. Kluwe

Jul 23 '05 #1
2 1557
Matthias Kluwe skrev:
Hi!

My problem looks like this:

#include <iostream>
#include <locale>

int main(int argc, char* argv[])
{
std::locale::global( std::locale( "deu" ) );
std::cout.imbue( std::locale() );
std::cout << 1000.4 << " " << 0.4 << std::endl;
return 0;
}

This is MS VC++ 7.1 here (explains the "deu" locale, it's the same with
"german").

Output is:

1,000.4 0,4

Now, this is confusing! I really expected

1.000,4 0,4
Shouldn't you at least be expecting 1.000,4 0,4 ?

I don't know what sort of function imbue() is
but it seems it just formats the numbers
as if it were financial calculations.
Any suggestions?

Regards,
M. Kluwe

Jul 23 '05 #2
> Matthias Kluwe skrev:
[...] Now, this is confusing! I really expected 1.000,4 0,4
Shouldn't you at least be expecting 1.000,4 0,4 ?
Didn't I say that?
I don't know what sort of function imbue() is
but it seems it just formats the numbers
as if it were financial calculations.


What sort of? Member of ios, I think. Should imbue (!) the stream with
the given locale ...

Anyway, I just checked with gcc 3.3.5 with the expected result, so
maybe I should consult a VC++ specific group.

Regards,
Matthias

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Timothy Smith | last post by:
hi there i need to set my locale so that when i output a number it's formatted with thousands grouped. the problem i've found is there doesn't seem to be very good cross platform support for...
4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
2
by: sprotty | last post by:
I'm writting some classes that deal with XML, and they need to be able to convert from strings to doubles and back. The problem is they should only accept/output strings valid in XML, that is...
1
by: Matthias Kluwe | last post by:
Hi! My problem looks like this: #include <locale> #include <iostream> int main(int argc, char* argv) { std::locale::global( std::locale( "deu" ) );
3
by: gelbeiche | last post by:
I have a question regarding the following small C program. #include <locale.h> int main() { char* loc = 0; char before,after; int i;
0
by: | last post by:
Hi all, running the following code as an console application: #include <locale> #include <iostream> #include <sstream> #include <tchar.h> using namespace std;
2
by: Daniele C. | last post by:
I will report a snippet from http://php.net/setlocale I spent about 2 seconds before thinking: can it really be? I mean, is there no way to set locale info per thread? And after a brief web...
5
by: Noah Roberts | last post by:
A lot of my code converts numeric values to strings using boost::lexical_cast, and thus, underneath, with <<. When I activate locales, the thousands separator turns on. We've deemed it not...
3
by: Mario Ruggier | last post by:
Hi, i had the following problem when installing py3.0rc1 on a Mac OS X 10.5.5. On this system, the default locale values are: $ locale LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C"
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.