Solved

convert float/double to string.

Posted on 2001-08-01
5
1,163 Views
Last Modified: 2008-03-10
How do I convert a floating point number to string?
0
Comment
Question by:Neelima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:Neelima
ID: 6343422
Will it help to the manipulation at bit level?
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6343518
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
 
LVL 33

Expert Comment

by:hongjun
ID: 6343561
0
 

Author Comment

by:Neelima
ID: 6343591
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
 
LVL 10

Accepted Solution

by:
makerp earned 50 total points
ID: 6343931
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
logging Access violation 6 21
What is atomic operation? 6 66
What is sub-make ? 2 87
Fill Null values 5 36
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question