PDA

View Full Version : OT: C/MFC support for internationalization of numbers


mflaster
October 13th, 2002, 03:55 PM
Please forgive this off-topic post. I'm posting here because I think this would be a place where someone could answer my question very easily. And I can't figure out where else to ask!

I have an application that is trying to copy numbers to the windows clipboard. Let's say I have 90 1/3. I do:
sprintf(buf,"%.3f", x)
and buf gets "90.333". I then send that into the clipboard. If I paste that into an Excel spreadsheet in the US, that works fine. But in Europe, Excel is "smart", sees the '.' as the thousand seperator, and converts it to 90333.

What is the proper function to generate a string from a number, that would generate 90,333 in Europe? Would CString s.format("%.3f", x) do this?

For paste, I use 'atof' to convert back. Is there a corresponding function that will expect "90,333" in Europe and "90.333" in the US?

Thanks in advance!

Mike

MMcM
October 13th, 2002, 03:55 PM
All the C runtime functions do what you want, just not by default.

The key bit that's missing is that you have to change the locale. When a program starts out, it's in the "C" locale. This has some standard definition, but essentially means that things act like they did on Unix in the '70s. Switch to an NLS locale and you get national settings. See the setlocale function. The empty string "" means the "native" environment, which is usually what you want. "C" goes back to the initial state.

In MFC, I often put setlocale(LC_ALL, ""); in InitApplication.

This is ANSI standard stuff and not a Microsoft "enhancement", for once.

mflaster
October 13th, 2002, 03:55 PM
Thanks! Actually just this morning I found out the same info from a German forum. setlocale(LC_ALL,"") does the trick.

BTW, the last dvdspy seems to do the right thing (with AR reporting from ZoomPlayer). I haven't set it up in my theater yet, however. When I do, I'll post! Thanks!

Mike