INFO: Clarification of fcvt() Function

Last reviewed: September 2, 1997
Article ID: Q42453

The information in this article applies to:
  • The C Run-time (CRT) included with: - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, 6.0ax - Microsoft C for OS/2, versions 5.1, 6.0, 6.0a - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 2.1, 2.2, 4.0,

         4.1, 5.0
    

SUMMARY

This article is meant to clarify the description of the fcvt() function in the "Microsoft C Optimizing Compiler: Run-Time Library Reference," version 5.1 manual, pages 251-252.

The fcvt() function converts a floating-point number to a null- terminated character string. The number of digits converted depends on the second parameter passed. This second parameter is called "count" for the remainder of this article.

The function is designed to return all the digits to the left of the decimal point, and then count digits to the right. Once the string is converted, all leading zeros are removed unless the number passed was zero (see example 4 below). The string will be terminated with the "/0" character. The decimal point is not included in the string, and its position can be obtained from the third parameter (see the documentation).

MORE INFORMATION

Based on this description, the following examples apply. In all cases, count = 8. The examples are as follows:

  1. Number passed: 3.667 String returned: "366700000\0"

    Nine digits are returned; one for the number to the left of the decimal point, eight more because of the count parameter.

  2. Number passed: 3.37E-08 String returned: "3\0"

    In this case, only "3" is returned because after the number is converted, all the leading zeros are removed.

  3. Number passed: 1.023E-12 String returned: "\0"

    In this case, a NULL string is returned because only zeros are left after the conversion, and these are all removed from the resulting string. If error checking were being performed, this would indicate a conversion underflow.

  4. Number passed: 0 String returned: "00000000\0"

    This is the only "special" case. Eight zeros are returned so that error checking can be performed easily.


Additional query words: 8.00 8.00c 9.00 9.10 10.00 10.10
Keywords : CRTIss kbfasttip
Version : MS-DOS:6.00ax,7.0; OS/2:6.0,6.00a; WINDOWS:1.0,1.5; WINDOWS NT:1.0,2.0,2.1,2.2,4.0,4.1,5.0
Platform : MS-DOS NT OS/2 WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.