Use snprintf() from stdlib.h. Worked for me.

double num = 123412341234.123456789; 
char output[50];

snprintf(output, 50, "%f", num);

printf("%s", output);
Answer from sujeeth.mr on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ c-program-for-double-to-string-conversion
C Program For Double to String Conversion - GeeksforGeeks
August 1, 2022 - We can use sprintf to add extra text (as required) to the string at the same time. ... // C Program to demonstrate // Double to String Conversion #include <stdio.h> int main() { double n = 456321.7651234; char str[100]; sprintf(str, "%f", n); ...
Discussions

Double to string and string to double
https://www.geeksforgeeks.org/convert-floating-point-number-string/ More on reddit.com
๐ŸŒ r/C_Programming
11
0
June 7, 2023
Convert double to string C++? - Stack Overflow
Possible Duplicate: How do I convert a double into a string in C++? I want to combine a string and a double and g++ is throwing this error: main.cpp: In function โ€˜int main()โ€™: main.cpp:40: err... More on stackoverflow.com
๐ŸŒ stackoverflow.com
converting string to a double variable in C - Stack Overflow
When the type is float or double, it prints 0. So why am I getting these ambiguous results? ... @Aidanc: The C standard would disagree with you. The first sentence in section 7.1.1 of the C standard, the 'definition of terms' part of the introduction to the standard library, says: A string is a ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Faster way to convert double to string, not using "%f"?
You mean something like ftoa() and itoa(). Basically under the hood, they do the same thing in the same way by using division and modulo as the functions you mentioned. More on reddit.com
๐ŸŒ r/C_Programming
22
1
October 16, 2022
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ double to string and string to double
r/C_Programming on Reddit: Double to string and string to double
June 7, 2023 -

I'd like a pair of functions atof and ftoa. The atof function converts a string (char *) into a double. The ftoa function converts a double into a string (char *). The first and most obvious requirement is that atof(ftoa(x)) = x for all double-precision floating point values x including special values (ยฑ0, ยฑโˆž and nan). My second requirement is that ftoa generate the shortest possible representation for all inputs (including denormalized floats) such that the first condition is satisfied, e.g. it can choose between %f and %g for this purpose.

Does such a pair of functions exist and, if so, where can I download the C source code to them?

๐ŸŒ
IBM
community.ibm.com โ€บ community โ€บ user โ€บ viewdocument โ€บ double-to-string-in-c
C/C++ - IBM Community
Your one-stop destination to learn and collaborate about the latest innovations in IBM C/C++ for z/OS compilers to develop high-performing C/C++ applications and system programs on z/OS while maximizing hardware use and improving application performance ยท In C++ , there are multiple functions ...
Find elsewhere
๐ŸŒ
IncludeHelp
includehelp.com โ€บ code-examples โ€บ c-double-to-string-conversion.aspx
C - Double to String Conversion Code Example
#include <stdio.h> int main() { // Create a double variable and assign value double x = 12345.678901; // Create a string to store string value char result[32]; // Using sprintf() to convert double to string sprintf(result, "%f", x); // Printing the value printf("Double valuue (x) : %f\n", x); ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ system.double.tostring
Double.ToString Method (System) | Microsoft Learn
... The string representation of the value of this instance. The following example uses the default Double.ToString() method to display the string representations of a number of Double values.
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 38507-double-string-conversion.html
double to string conversion
April 25, 2003 - Originally posted by penney Actually I believe that if you are converting a double then you should use: sprintf(str,"%lf", yourdouble); /* and whatever precision spec's you want */ %f is for floats and %lf for doubles. This is undefined behavior for pre-C99 implementations.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ c_standard_library โ€บ c_function_strtod.htm
C library - strtod() function
endptr โˆ’ It is a pointer to a charter pointer and used to store the pointer to the first character after the numeric value. This function returns the converted double-precision floating-point number. If the input string is not a valid, it returns 0.
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ faster way to convert double to string, not using "%f"?
r/C_Programming on Reddit: Faster way to convert double to string, not using "%f"?
October 16, 2022 -

Have to output millions of doubles to text files, so wondering if there is a faster way to convert double => text, besides using %f in one of many settings printf, sprintf, others I could probably find.

In the way that you could convert an int to text by using modulo and division to get the decimal digits. I assume that's faster than running through %d.

EDIT: I finally settled on %d and multiplying the double values by 1000000, converting to int, then converting back on the receiving end. More than enough precision for my specific application, not really elegant, but the time saving is significant. The double->int and reverse conversions are just a few instructions, much faster than converting the double to a string and back to double.

๐ŸŒ
All About Circuits
forum.allaboutcircuits.com โ€บ home โ€บ forums โ€บ embedded & programming โ€บ programming & languages
Convert double to string in C | All About Circuits
May 14, 2010 - Are you just trying to find the amount of characters in the var? If you want the size in bytes, you can use sizeof(); then divide to get the # of characters. ... There's no unique string representation of a given double, as there are lots of approximate choices.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-do-i-convert-a-double-into-a-string-in-cplusplus
How do I convert a double into a string in C++?
April 11, 2025 - Using the to_chars() function, we have converted the given double value to the character and stored them in the buffer. The above step returns a pointer and an error code (ec). Then using the string constructor, we convert the character in the ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ convert-floating-point-number-string
Convert a floating point number to string in C - GeeksforGeeks
July 23, 2025 - Write a C function ftoa() that converts a given floating-point number or a double to a string. Use of standard library functions for direct conversion is not allowed. The following is prototype of ftoa().
๐ŸŒ
Quora
quora.com โ€บ Can-we-convert-double-to-string-in-C
Can we convert double to string in C++? - Quora
Answer (1 of 5): Can we convert double to string in C++? Yes, you can. std::to_string includes an overload for [code ]double[/code]. [code]#include #include int main() { std::string out = std::to_string(0.50); std::cout
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ hardware and peripherals โ€บ raspberry pi pico โ€บ sdk
How to convert a double to a C string? - Raspberry Pi Forums
set_pico_float_implentation(my_app none) in your CMakeLists.txt, as the printf implementation for floats uses the floating point code! ... Thanks everybody! sprintf() indeed works with doubles and it solved by problem. However, I am having problems with formatting int64 values.
๐ŸŒ
Programiz
programiz.com โ€บ cpp-programming โ€บ string-float-conversion
C++ String to float/double and vice-versa | Programiz
April 23, 2020 - We can convert float and double to string using the C++11 std::to_string() function.
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ how do i convert double to string?
r/C_Programming on Reddit: how do i convert double to string?
May 17, 2021 - You don't need to differentiate floats verses doubles because float is implicitly widened to double when passed to variable (or unspecified) argument functions. ... Slow and standard or really fast? For slow see the snprintf answer. For fast see https://github.com/ulfjack/ryu or grisu ... Wrong direction. ... Converting string to char causes error, help!