title: Set precision of a double variable in 'string to double' using lexical cast
body: <p>I have a string which has the value <strong>"496934.079"</strong> . 
  I use <strong>boost::lexical_cast ()</strong> to convert this into a double variable (named <strong>pVar</strong>). </p>
  
  <p>However the value stored in pVar after conversion is <strong>"496934"</strong> not <strong>"496934.079"</strong>. The digits after the decimal points are missing. I have read about <strong>std::setprecision()</strong> for writing the double value with needed precision in the output window <a href="https://stackoverflow.com/a/22515674/6260748">here</a>. But it only displays value with the given precision and it does not saves it in the variable with the given prescision.</p>
  
  <p>But I want to store the double value exactly as it is in the string variable <strong>str</strong> so that the value in pVar is <strong>"496934.079"</strong>. How can I store the value in the variable with same precision as in the input string so that I can use the variable for further processing?</p>
  
  <p>My code snippet is:</p>
  
  <pre><code>int func()
  {
      string str = "496934.079";
      double pVar = boost::lexical_cast&lt;double&gt; (str);
      cout &lt;&lt; pVar &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> This conversion from string to float is part of the code I am developing which parses values from a text file line-by-line and writes them into another file (.pcd format). I am adding the entire code I use for this conversion for reference.</p>
  
  <pre><code>int txt2pcd()
  {
      ifstream is("input_text_file.txt");                                         //read input text file
      string str;
      using namespace boost::algorithm;
      pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr point_cloud_ptr (new pcl::PointCloud&lt;pcl::PointXYZ&gt;);
      while(getline(is, str))                                                     //parsing the text file contents line-by-line
      {   
          std::string s = str.c_str();
          std::vector&lt;std::string&gt; result;            
          std::istringstream iss(s);
          for(std::string s; iss &gt;&gt; s; )
              result.push_back(s);
  
          pcl::PointXYZ point;
  
          point.x = boost::lexical_cast&lt;double&gt; (result[0]);                      //string to float conversion for adding the X coordinate of the point
          point.y = boost::lexical_cast&lt;double&gt; (result[1]);                      //string to float conversion for adding the Y coordinate of the point
          point.z = boost::lexical_cast&lt;double&gt; (result[2]);                      //string to float conversion for adding the Z coordinate of the point
  
          point_cloud_ptr-&gt;points.push_back (point);
          point_cloud_ptr-&gt;width = (int) point_cloud_ptr-&gt;points.size ();
          point_cloud_ptr-&gt;height = 1;            
      }   
      pcl::io::savePCDFile ("output_pcd_file.pcd", *point_cloud_ptr, false);    //this is where the converted float values are stored (with digits altered after decimal point when compared to text file)
      return 0;
  }
  </code></pre>
  
  <p>Below are few sample few lines from the text file and the corresponding lines from the converted '.pcd' file.</p>
  
  <p><strong>In text file:</strong></p>
  
  <p>496934.999 5419547.239 265.179</p>
  
  <p>496933.981 5419542.579 263.819</p>
  
  <p>496934.891 5419545.399 264.849</p>
  
  <p>496934.939 5419546.329 265.111</p>
  
  <p>496934.829 5419544.489 264.781</p>
  
  <p><strong>In '.pcd' file</strong> (corresponding values resulting from <em>boost::lexical_cast ()</em>)</p>
  
  <p>496935 5419547 265.17899</p>
  
  <p>496933.97 5419542.5 263.819</p>
  
  <p>496934.91 5419545.5 264.849</p>
  
  <p>496934.94 5419546.5 265.11099</p>
  
  <p>496934.84 5419544.5 264.78101</p>
  
  <p>Note that the values are either rounded off or the digits after decimal point are altered in the output '.pcd' file. What could be the reason for this?</p>