use the
modf
function. This splits your double into the integer part and the fractional part.
Then, take the fractional part and multiply it by a power of 10 in your case, 10^2. Then use the
floor
function to return just the integer portion of that number and then divide it by the power of 10. Then, add the integer and fractional parts back together.
double dblOriginal, dblIntPortion, dblFractPortion;
dblOriginal = 25.4938;
dblFractPortion = modf(dblOriginal, &dblIntPortion);
dblFractPortion = pow(10.0,2) * dblFractPortion;
dblFractPortion = floor(dblFractPortion);
dblFractPortion = dblFractPortion / pow(10.0,2);
cout << (dblIntPortion + dblFractPortion);
This should give you what you're looking for (though I'm a bit rusty on c++).