Hi,

i'm getting only one digit after floating point after conversion from string to float. Have tryed from standart functions to i don't know.. the problems is that conversion whatever it would be (strtod(), stringstream >> float, atof(), don't even rembember all other wacky ways to do that) brings me only one or none (if i have number.00) digits after floating point.

Would be very happy to hear something that might help..

p.s. oh, if that matters - i get string from file via getline..

You're going to have to post some code so that we can see what you are doing. Otherwise, all we can do is take a shot in the dark.

#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <stdlib.h>
#include <cstring>
using namespace std;
//
main()
{
    string sKBP, sE, sBP;
    int iDS;
    cout << "Name of the file:\n";
    cin >> sBP;
    sKBP += sBP + ".csv"; 
    cout << "In which column data is?\n";
    cin >> iDS;
    const char *ccBP = sKBP.c_str (); 
    ifstream ifsB(ccBP /*"tete.csv"*/);
    if(!ifsB)
        cout << "bla bla..\n";
    else
        {
        while (getline(ifsB, sE))
            {
            istringstream issE(sE);
            string sL;
            int iK=0;
            while(getline(issE, sL, ';'))
                {
                iK++;
                if (iK == iDS)
                    {
                    sL.erase(sL.begin() + sL.find(','));
                    /*char *cNL=new char[sL.size()+1];
                    cNL[sL.size()]=0;
                    memcpy(cNL, sL.c_str(), sL.size());
                    double test = strtod(cNL, NULL);*/
                    /*stringstream ssTF(sL);
                    float fTEST;
                    ssTF << sL;
                    ssTF >> fTEST;*/
                    //sL.push_back('\0');
                    //const char *ccL = sL.c_str();
                    cout << "String: " << /*atof(ccL)*/ /*fTEST*/ sNL << " length: " << sL.length() << "\n";
                    }
                }
            }
        }
}

that is the code..

try cout << setprecision(10); where you need to include iomanip as a header

works with your solution :) but in file i have only 2 digits after floating point, if i setprecision(10) - i have 4 digits after floating point, first two are ok, but others are from heaven - there is no such data in file.. another thing that is - i get the precision in cout, but not in counting like variable * variable..

So still need to figure out where the hook is..

This article has been dead for over six months. Start a new discussion instead.