I've got a small C++ problem. First of all, "my" language is Java, so I'm new to C++. I have this function:
double readableDouble( double input )
{
return (int)(input*100+0.5)/100.0;
}
As you can see, nothing special. Now I call the function from another function (in the same class):
cout << readableDouble(4434.21121131234323243) <<endl; // result: 4434.22 all okay
cout << readableDouble(tempTrack.getLenght()/1000.0); // result: 30.56 all okay
string lenght = boost::lexical_cast<string>(readableDouble((tempTrack.getLenght()/1000.0))); // result 30.55999999999982. expected: 30.56
getLenght() returns a double. (same double for both calls)
I am not quite sure how this is happening?
.