PRB: gcvt() Generates Exponential Notation for 0.0x

ID Number: Q37794

5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

SYMPTOMS

The gcvt() function returns an exponential number in the string,

even if the number fits in the specified precision, when the number

is of the form 0.0x, where x is any digit(s).

CAUSE

This is expected behavior for gcvt() as documented in the online

help supplied with the Microsoft C compiler versions 6.0, 6.0a, and

6.0ax.

RESOLUTION

Use fcvt() to place a floating-point formatted number in a string.

More Information:

The following code demonstrates this behavior:

Sample Code

-----------

// Compile options needed: none

#include <stdio.h>

#include <stdlib.h>

char buffer[50];

int precision=20;

void main(void)

{

gcvt(-0.1123,precision,buffer); /* Will give decimal output.*/

printf("buffer ........\"%s\"\n",buffer);

gcvt(-0.0123,precision,buffer); /* Will give exponential output.*/

printf("buffer ........\"%s\"\n",buffer);

}

Additional reference words: 5.10 6.00 6.00a 6.00ax