C++ Convert string to float
<p>I am trying to convert a string based number to float. Unfortunately I am getting either the rounded off value or truncated value. How can I fix this.</p>

<pre><code>    std::string text = "199102.92";
    float v = std::stof(text);
    std::cout&lt;&lt;v&lt;&lt;std::endl;
</code></pre>

<p>This results in 199103
Even if I use setprecision and fixed then it only affects the output stream but the value passed into the float variable remains 199103. How can i resort this problem.</p>

<p>I have also used stringstream in c++ but results seem to be the same except it just displays off well. </p>

<p>I need to preserve the decimal upto 2 places. </p>

<p>I have used stof,stod, they all do the same thing.</p>

<p>You may assume that I am working with currencies.</p>