intPart
is still a double
, and gets formatted for text output with the default rules for double
s (just because it's logically an integer value doesn't mean C++ is willing to spend the effort to do runtime checks to tweak precision dynamically; that's your responsibility if you choose to take it on).
To fix, you can either cast it to an integer type (risks losing data if the integer component is larger than 64 bits), or you can use iomanip
manipulators to change the formatting rules for floating point values so they omit the data after the decimal point that you know will not exist, e.g. with:
cout << fractPart << endl << std::fixed << std::setprecision(0) << intPart << endl << stringIntPart;
(I left the std::
prefixes in there on the added stuff, because using namespace std;
is a bad idea, and I prefer being explicit)