我正在使用GetNumberFormat
函数来获取格式化的数字,但它返回非英语语言环境的垃圾值。
它适用于英语语言环境。
代码:
int FormatNumber(double number, long nbrDecs, char* destBuf, int bufSize)
{
char infoBuf[3];
char decimalSep[10];
char thousandSep[10];
char sourceNbr[50];
NUMBERFMT* customFormat = NULL;
UINT defDigits;
LCID lcid;
int status;
lcid = GetUserDefaultLCID();
status = GetLocaleInfo(lcid, LOCALE_IDIGITS, infoBuf, 3);
if (status == 0){
return status;
}
defDigits = atoi(infoBuf);
if (defDigits != (UINT) nbrDecs){
customFormat = new NUMBERFMT;
customFormat->NumDigits = nbrDecs;
status = GetLocaleInfo(lcid, LOCALE_ILZERO, infoBuf, 3);
customFormat->LeadingZero = atoi(infoBuf);
status = GetLocaleInfo(lcid, LOCALE_SGROUPING, infoBuf, 3);
customFormat->Grouping = atoi(infoBuf);
status = GetLocaleInfo(lcid, LOCALE_STHOUSAND, thousandSep, 10);
customFormat->lpThousandSep = thousandSep;
status = GetLocaleInfo(lcid, LOCALE_SDECIMAL, decimalSep, 10);
customFormat->lpDecimalSep = decimalSep;
status = GetLocaleInfo(lcid, LOCALE_INEGNUMBER, infoBuf, 3);
customFormat->NegativeOrder = atoi(infoBu`enter code here`f);
}
sprintf_s(sourceNbr, sizeof(sourceNbr),"%f", number)
status = GetNumberFormat(lcid, 0, sourceNbr, customFormat, destBuf, bufSize);
// here destBuf is having the junk value.
if (customFormat != NULL)
delete customFormat;
return status;
}
我正在获得垃圾价值。这里destBuf
返回垃圾值。