How to convert full-width numbers to half-width numbers (225136)



The information in this article applies to:

  • Microsoft Windows 98, when used with:
    • the operating system: Microsoft Windows 95
    • the operating system: Microsoft Windows 98
    • Microsoft Visual C++, 32-bit Professional Edition 5.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual Basic Enterprise Edition for Windows 5.0
    • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q225136

SUMMARY

When converting the full-width Unicode numbers (U+FF10-U+FF19) to standard half-width numbers (U+0030-U+0039)while using WideCharToMultiByte, it fails to do the conversion on Windows 95 and 98. One should use the API LCMapString with flag LCMAP_HALFWIDTH to convert the full-width characters to half-width characters.

MORE INFORMATION

Since the W version of this API does not work on Windows 95 and Windows 98 one needs to convert the full-width characters from Unicode to proper DBCS strings, and then call LCMapString to do the conversion. Here is a sample working with full-width Unicode numbers in traditional Chinese, simplified Chinese, Japanese and Korean:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>

void main(void)
{
	WCHAR T[2] = {65301, 0};
	TCHAR dbcs[3], conv[3];
	WideCharToMultiByte(CP_ACP, 0, T, -1, dbcs, sizeof(dbcs), NULL, NULL);
	int nRes = LCMapString(LOCALE_USER_DEFAULT, LCMAP_HALFWIDTH, 
                                                      dbcs,sizeof(dbcs),conv,sizeof(conv));
	printf("%s\n",conv);
}
To make the conversion work for Windows 95 and Windows 98, install one of the four code pages (950 for traditional Chinese, 936 for simplified Chinese, 932 for Japanese and 949 for Korean) on the system and explicitly set the code page and locale ID parameters in the above API calls.

REFERENCES

For more information about installing a code page, click the following article number to view the article in the Microsoft Knowledge Base:

164948 How to install a code page


Modification Type:MajorLast Reviewed:12/28/2005
Keywords:kbDSXGlobal2003Swept kbDBCS kbhowto kbLocalization kbNLS kbUnicode KB225136