HOWTO: Convert Full-Width Numbers from Fareast to Standard

ID: Q225136


The information in this article applies to:


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 on all Fareast Windows 95 and Windows 98 (simplified and traditional 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, one needs to install one of the four Fareast code pages (932 for Japanese, 936 for simplified Chinese, 949 for Korean and 950 for traditional Chinese) on the system and explicitly set the code page and locale ID parameters in the above API calls.


REFERENCES

Please read the following article for more details on installing a code page:

Q164948 HOWTO: Installing a Code Page

Additional query words:


Keywords          : kbNLS kbUnicode kbVC500 kbVC600 kbWinOS95 kbWinOS98 kbLocalization kbDBCS 
Version           : WINDOWS:6.0,97,97sp1,97sp2,97sp3
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: June 4, 1999