Skip to content
Related Articles

Related Articles

Improve Article

What is the best way in C to convert a number to a string?

  • Difficulty Level : Easy
  • Last Updated : 02 Jun, 2017

Solution: Use sprintf() function.

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.




#include<stdio.h>
int main()
{
    char result[50];
    float num = 23.34;
    sprintf(result, "%f", num);
    printf("\n The string for the num is %s", result);
    getchar();
}

You can also write your own function using ASCII values of numbers.

My Personal Notes arrow_drop_up
Recommended Articles
Page :