读书人

新手请问:C++中对小数点后两位进行四

发布时间: 2013-09-09 20:31:09 作者: rapoo

新手请教:C++中对小数点后两位进行四舍五入,结果出现问题
#include<iostream>
#include<stdlib.h>
using namespace std;
float x;
void main()
{
cin>>"a\n";
cout<<"getA(a):"<<endl;
system("pause");

}
void getA(float x)
{
x= int((x+0.005)*100.)/100;
};
c++ ,c++builder
[解决办法]

#include<iostream>
#include<cstdlib>

using namespace std;
void getA(double& x);

int main()
{
cout << "Input a: ";
double x;
cin >> x;
getA(x);
cout<< "getA(a): " << x <<endl;
system("pause");
return 0;
}

void getA(double& x)
{
x= int((x+0.005)*100) / 100.0;
};

读书人网 >C++

热点推荐