• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1170
  • Last Modified:

convert float/double to string.

How do I convert a floating point number to string?
0
Neelima
Asked:
Neelima
  • 2
  • 2
1 Solution
 
NeelimaAuthor Commented:
Will it help to the manipulation at bit level?
0
 
hongjunCommented:
Try this (Converting int to string)

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int num=999;
    char str[6]; // a 5 character string

    sprintf(str, "%d", num);

    printf("%s\n", str);

    return EXIT_SUCCESS;
}

Notice of the use of %d for integer. Change that to others for double and long.

hongjun
0
 
hongjunCommented:
0
 
NeelimaAuthor Commented:
If I use those options then there is rounding after 6 digits after the decimal point.I dont want that.And I dont want to give any precision too.What I want to know is if this can be manipulated at bit level?
0
 
makerpCommented:
use this

char *_fcvt( double value, int count, int *dec, int *sign );

value: Number to be converted
count: Number of digits after decimal point
dec  : Pointer to stored decimal-point position
sign : Pointer to stored sign indicator


#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   int  decimal, sign;
   char *buffer;
   double source = 3.1415926535;

   buffer = _fcvt( source, 7, &decimal, &sign );
   printf( "source: %2.10f   buffer: '%s'   decimal: %d   sign: %d\n",
            source, buffer, decimal, sign );
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now