KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q42453: Clarification of fcvt() Function

Article: Q42453
Product(s): See article
Version(s): 5.00 5.10 | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | s_quickc | mspl13_c
Last Modified: 17-MAY-1989

This article is meant to clarify the description of the fcvt()
function in the "Microsoft C for the MS-DOS Operating System: Run-Time
Library Reference," 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).

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.67E-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.

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.

Copyright Microsoft Corporation 1986-2002.