Microsoft KB Archive/185280

= FIX: Printf Gives Unexpected Results for Doubles on WinCE =

Article ID: 185280

Article Last Modified on 5/10/2001

-

APPLIES TO


 * Microsoft Visual C++ for Windows CE 1.0

-



This article was previously published under Q185280



SYMPTOMS
When you use any of the printf C run-time routines (printf, _vstprintf, _stprintf, and so on) with the "%f" format specifier, you get unexpected results. The printf C run-time routines return the floating-point format specifier without the leading '%' instead of the text representation of the number. For example, the following code gives the result "f" instead of "1.23456789": _stprintf(pBuffer, TEXT("%f"), 1.23456789);



CAUSE
This is a bug in the printf C run-time routines. The printf routines for Windows CE do not support floating-point numbers.



RESOLUTION
This has been fixed in version 2.0 of Visual C++ for Windows CE. To work around this problem in version 1.0, you must manually convert the floating- point number. You can use the _gcvt function to convert the floating-point number to an ANSI string, and then use the "%S" format specifier in a printf routine to convert the ANSI string to UNICODE.

For example, replace the following code: _stprintf(pBuffer, TEXT("%f"), 1.23456789); with: char pTemp[256]; _gcvt(1.23456789,9,pTemp); _stprintf(pBuffer, TEXT("%S"), pTemp);



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been corrected in Visual C++ for Windows CE, 2.0.

Additional query words: kbnokeyword kbwince100fix

Keywords: kbbug kbfix KB185280

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.