- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I convert a double into a string in C++?
A double can be converted into a string in C++ using std::to_string. The parameter required is a double value and a string object is returned that contains the double value as a sequence of characters.
A program that demonstrates this in C++ is given as follows.
Example
#include <iostream> #include <string.h> using namespace std; int main() { double d = 238649.21316934; string s = to_string(d); cout << "Conversion of double to string: " << s; return 0; }
Output
The output of the above program is as follows.
Conversion of double to string: 238649.213169
Now let us understand the above program.
A variable d of double type is initialized with a value 238649.21316934. This double value is converted to a string using to_string. Finally this is displayed. The code snippet that shows this is as follows.
double d = 238649.21316934; string s = to_string(d); cout << "Conversion of double to string: " << s;
- Related Articles
- How do I convert a string into an integer in JavaScript?
- How can I convert string to double in C/C++?
- How to convert a double value into a Java String using format method?
- How to convert a double value into a Java String using append method?
- How do I convert a string to a number in Python?
- How do I convert a number to a string in Python?
- How do I convert a Swift array to a string?
- How to convert a string into int in C#?
- How to convert a double value to String in Java?
- Java Program to convert Double into String using toString() method of Double class
- How do I split a multi-line string into multiple lines?
- How to Convert Double to String to Double in Java?
- How to convert a list of characters into a string in C#?
- How to convert a Double array to a String array in java?
- Convert a String to a double type number in Java

Advertisements