C++如何输出小数点后面的数

2025-06-28 00:02:15
推荐回答(4个)
回答1:

字符串输入:
#include
using namespace std;
int main()
{
char s[22];
int i=0;
cin>>s;
while(1)
{
if(s[i++]=='.')break;
}
while(s[i])
cout< cout< return 0;
}

 

double型输入:
#include
using namespace std;
int main()
{
double in;
int n;
cin>>in;
n=(int)((in-(int)in)*1000000);//小数部分
while(1)
{
if(n%10!=0)break;
n/=10;  //去掉后面的0
}
cout< return 0;
}

回答2:

回答3:

float a=3.1313f;
printf("%f",a-(int)a);

回答4:

是输入字符串还是双精度 ?