H
Hank Stalica
I'm having this weird problem where my code does the following
conversion from string to float:
27000000.0 -> 27000000.00
2973999.99 -> 29740000.00
2989999.13 -> 2989999.25
The number on the left is the string I get after tokenizing a bigger
string. The number on the right is the number I get after the conversion.
I've tried two different ways of converting, one way the older C way
using atof, and another more C++ way. Either way, I get the same
result. Can anyone shed some light on this for me?
Here's the code:
string token;
string tokens[14];
stringstream iss;
getline(fin,bfr);
while (getline(fin, bfr))
{
iss << bfr;
i = 0;
while (getline(iss, token, ','))
{
tokens[i++] = token;
}
std::istringstream b(tokens[0]);
b >> price;
//price = atof(tokens[0].c_str());
conversion from string to float:
27000000.0 -> 27000000.00
2973999.99 -> 29740000.00
2989999.13 -> 2989999.25
The number on the left is the string I get after tokenizing a bigger
string. The number on the right is the number I get after the conversion.
I've tried two different ways of converting, one way the older C way
using atof, and another more C++ way. Either way, I get the same
result. Can anyone shed some light on this for me?
Here's the code:
string token;
string tokens[14];
stringstream iss;
getline(fin,bfr);
while (getline(fin, bfr))
{
iss << bfr;
i = 0;
while (getline(iss, token, ','))
{
tokens[i++] = token;
}
std::istringstream b(tokens[0]);
b >> price;
//price = atof(tokens[0].c_str());