Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;setprecision(设置小数位数1-10)_C++ - Fatal编程技术网

C++ C++;setprecision(设置小数位数1-10)

C++ C++;setprecision(设置小数位数1-10),c++,C++,编辑所以我发布了我正在使用的HTML和代码。我没有得到任何错误,但它对小数的数量没有任何不同 因此,我有一个表单,用户将选择1到10来决定一个计算将显示多少小数以显示“答案”。我正在尝试使用setprecision,请帮助我清理代码 int decDropDown; getvar("decDropDown", dest4,buffer); decDropDown = atoi(dest4); // The decimal value if(decDropDown == 1) {

编辑所以我发布了我正在使用的HTML和代码。我没有得到任何错误,但它对小数的数量没有任何不同

因此,我有一个表单,用户将选择1到10来决定一个计算将显示多少小数以显示“答案”。我正在尝试使用setprecision,请帮助我清理代码

int decDropDown;

getvar("decDropDown",  dest4,buffer);

decDropDown = atoi(dest4); // The decimal value

if(decDropDown == 1)
{
    cout<<setprecision(decDropDown)<<answer<<endl;
}
else if(decDropDown == 2)
{
    cout<<setprecision(decDropDown)<<answer<<endl;
}
int下拉列表;
getvar(“decDropDown”,dest4,buffer);
decDropDown=atoi(dest4);//十进制值
如果(decDropDown==1)
{

cout该代码没有问题,但是您应该使用它,它将节省时间

cout<<setprecision(decimalValue)<<answer<<endl;
cout
#包括
#包括
int main()
{ 
双倍=3.13;
//使用IOManip标头:

std::cout您有什么错误?是否包含iomanip?为什么不直接执行
setprecision(小数点值)
?问题在于您没有向我们展示的代码。您应该包括错误的描述,而不是让我们猜测。除了结尾没有额外的双引号。我尝试将代码“std::cout”的这一部分交换到您的项目中。我提供了某种“概念证明”。如果您运行我给你的代码,你会理解它的作用。在堆栈溢出的情况下,我们试图用鼓励ASK学习自己的方式回答问题。@ MartyHuggins,它也可以让你知道C++中的数字类型是如何工作的。
cout<<setprecision(decimalValue)<<answer<<endl;
#include <iostream>
#include <iomanip>

int main()
{ 
    double whatever = 3.13;
    // using IOManip header:
    std::cout << std::setprecision(100) << std::fixed << whatever << std::endl; 
}