Tutorials  Articles  Notifications  Login  Signup


RK

Rajan Kumar

Founder at HackersFriend Updated Jan. 16, 2020, 12:47 a.m. ⋅ 1434 views

Convert a number to a string in C - best way


We can use sprintf() function to conver any number to string in C. Number can be any integer or float.

Here is an implementation of it.

#include<stdio.h> 
int main() 
{ 
	char final[100]; 

	float number = 98.12;
 
	sprintf(final, "%f", number);

	printf("\nString of given number is %s", final); 

	return 0;
} 

 

 



HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account