Discussion:
GetNumberFormat - without decimals ?
(too old to reply)
R.Wieser
2020-04-04 16:19:01 UTC
Permalink
Hello all,

I would like to display an (unsigned) integer number according to the
current locale, and thought "GetNumberFormatA" would do the job. Alas,
for some reason it always appends ".00", two fractional digits my integer
number does not have and I cannot use.

Although I've been able to fill in a "NUMBERFMTA" structure myself (six
GetLocalInfoA calls, plus parsing of the LOCALE_SGROUPING result), but that
takes quite a bit of work, as I've not seen a way to retirieve it directly.

Question: On XP, is there an easy way to get the "GetNumberFormatA" /not/ to
add decimals, or is there a way to retrieve the "NUMBERFMTA" data directly,
so I only have to set the "NumDigits" field to zero ?

Regards,
Rudy Wieser
JJ
2020-04-04 17:03:35 UTC
Permalink
Post by R.Wieser
Hello all,
I would like to display an (unsigned) integer number according to the
current locale, and thought "GetNumberFormatA" would do the job. Alas,
for some reason it always appends ".00", two fractional digits my integer
number does not have and I cannot use.
Although I've been able to fill in a "NUMBERFMTA" structure myself (six
GetLocalInfoA calls, plus parsing of the LOCALE_SGROUPING result), but that
takes quite a bit of work, as I've not seen a way to retirieve it directly.
Question: On XP, is there an easy way to get the "GetNumberFormatA" /not/ to
add decimals, or is there a way to retrieve the "NUMBERFMTA" data directly,
so I only have to set the "NumDigits" field to zero ?
Regards,
Rudy Wieser
Without specifying NUMBERFMT manually, the number of fractional digits would
be based on the specified locale. So, try checking each eavilable locales to
find the one with zero number of fractional digit. If there is one, then use
the locale constant to format a number without any fractional digits. I
think it should work - assuming there's a locale which has zero number of
fractional digit.
R.Wieser
2020-04-04 17:51:00 UTC
Permalink
JJ,
Post by JJ
So, try checking each eavilable locales to
find the one with zero number of fractional digit.
Yikes.
Post by JJ
assuming there's a locale which has zero number
of fractional digit.
For which case I would need to write a fall-back. :-)

But, thanks for the suggestion. I had not thought of it.

Regards,
Rudy Wieser
R.Wieser
2020-04-05 11:47:19 UTC
Permalink
Post by R.Wieser
Hello all,
I would like to display an (unsigned) integer number according to the
current locale, and thought "GetNumberFormatA" would do the job. Alas,
for some reason it always appends ".00", two fractional digits my integer
number does not have and I cannot use.
Somewhere along the road I realized that I could ask the system how many
fractional digits are returned using
'GetLocaleInfo,LOCALE_USER_DEFAULT,LOCALE_RETURN_NUMBER or LOCALE_IDIGITS',
and just trim that many characters +1 (for the decimal seperator char) from
the end of the string. Not really pretty, but as far as I can tell should
work (If someone sees a problem I would (ofcourse) like to hear).

Regards,
Rudy Wieser

Loading...