GetNumberFormat for integer values
-
I'm trying to use the GetNumberFormat API for integer values. No fractional digits and no decimal seperator should appear in the output. I want to use the API to account for locale settings. The results should look similar to the file sizes in Explorer's File Properties dialog.
-
I'm trying to use the GetNumberFormat API for integer values. No fractional digits and no decimal seperator should appear in the output. I want to use the API to account for locale settings. The results should look similar to the file sizes in Explorer's File Properties dialog.
Ok, so what's the problem? Do you have a code snippet that is producing a compiler or run-time error?
NUMBERFMT fmt = {0,0,3,"",",",1};
char szNumber[16] = "123456",
szFmtNumber[16];
GetNumberFormat(GetThreadLocale(), 0, szNumber, &fmt, szFmtNumber, sizeof(szFmtNumber)); -
Ok, so what's the problem? Do you have a code snippet that is producing a compiler or run-time error?
NUMBERFMT fmt = {0,0,3,"",",",1};
char szNumber[16] = "123456",
szFmtNumber[16];
GetNumberFormat(GetThreadLocale(), 0, szNumber, &fmt, szFmtNumber, sizeof(szFmtNumber));I don't get an error, I don't want to use the
NUMBERFMT
structure but use the user locale settings for the number format, only without the fractional part. Maybe there's an API to get the number format, but apparently it's notGetNumberFormat
:doh: And I wanted to avoid having to callGetLocaleInfo
for each member of theNUMBERFMT
struct. -
I don't get an error, I don't want to use the
NUMBERFMT
structure but use the user locale settings for the number format, only without the fractional part. Maybe there's an API to get the number format, but apparently it's notGetNumberFormat
:doh: And I wanted to avoid having to callGetLocaleInfo
for each member of theNUMBERFMT
struct.You can't eat your cake and have it too. The whole premise behind using locale settings is so that applications won't make assumptions as to what the user wants. If the user sets up their machine to have , (comma) as the thousands separator, you mustn't override that with something else, or remove it altogether. Same goes for fractional digits, decimal points, negativity, etc. I have a slightly similar situation with the project I am working on. It's a scheduling application, which makes heavy use of dates and times. The application has to work no matter what locale it is in, or what regional settings are in place. Luckily, the NLS functions minimize the pain.