double num = 0.07;
while(num > 0 && num < 0.99999999999999999)
{
std::cout<<"*******************"<<std::endl;
std::cout<<"original number = "<<num<<std::endl;
short s = 0;
num*=(double)10;
std::cout<<"\noriginal number*10 = "<<num<<std::endl;
s = num;
std::cout<<"\noriginal number to int = "<<s<<std::endl;
num = num - s;
std::cout<<"\noriginal number*10 - int = "<<num<<std::endl;
std::cout<<"*******************"<<std::endl;
if (s==7)
break;
}
Output
*******************
original number = 0.07
original number*10 = 0.7
original number to int = 0
original number*10 - int = 0.7
*******************
*******************
original number = 0.7
original number*10 = 7
original number to int = 7
original number*10 - int = 8.88178e-016 <-- Here this is weird i supposed it gives 0
*******************
So, you want to convert 0.9997 into a string? I didn't understand, you can cast into integer or use some rounding method, followed by conversion into string.
To compare two doubles, compute the algebraic distance between them.