INF: Clarification of fcvt() Function

ID Number: Q42453

5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

This article is meant to clarify the description of the fcvt()

function in the "Microsoft C Optimizing Compiler: 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).

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

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00