#include <iostream> #include <string.h> #include <iomanip> using namespace std; float Number(int nInput ) { float k = 0.0f; k = nInput; return k; } int main () { int nInput = 0; cin>>nInput; cout <<"Number = " <<setiosflags(ios::fixed) <<Number(nInput) <<endl; cout <<"Number = " <<setiosflags(ios::fixed) << nInput <<endl; return 0 ; } int 转化为 float,然后输出后面为零的小数! 主要注意 setiosflags(ios::fixed) 的运用 包含在<iomanip>头文件内