After converting double to string using to_string() it shows invalid string length.

I've converted a double value into string using to_string(). But after converting when I check the length of the string it returns an invalid value.

1
2
3
4
5
6
7
8
9
10
11
12
#include <bits/stdc++.h>

using namespace std;

int main()
{
    double n=123.456;
    string s=to_string(n);
    int l=s.length();
    cout<<l<<endl;     //It prints 10. Where the string length is 6.
    return 0;
}


Why?
Last edited on
The to_string function appears to be appending 0s when converting to string. If I print out the value of s, it's 123.456000 (The decimal counts too)
Topic archived. No new replies allowed.