Microsoft KB Archive/42453

{| = INFO: Clarification of fcvt Function =
 * width="100%"|

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 &quot;Microsoft C Optimizing Compiler: Run-Time Library Reference,&quot; 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 &quot;count&quot; 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 &quot;/0&quot; 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: &quot;366700000\0&quot;

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: &quot;3\0&quot;

In this case, only &quot;3&quot; is returned because after the number is  converted, all the leading zeros are removed. 3. Number passed: 1.023E-12 String returned: &quot;\0&quot; 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: &quot;00000000\0&quot;

This is the only &quot;special&quot; 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         : kbCRT kbVC 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
 * }