C++ setprecision (setting number of decimals 1-10) -


edit posted html , code i'm using. i'm not getting errors it's not doing different amount of decimals?

so have form user pick 1 through 10 decide how many decimals displayed calculation display "answer". i'm trying use setprecision, please me clean code

int decdropdown;  getvar("decdropdown",  dest4,buffer);  decdropdown = atoi(dest4); // decimal value  if(decdropdown == 1) {     cout<<setprecision(decdropdown)<<answer<<endl; } else if(decdropdown == 2) {     cout<<setprecision(decdropdown)<<answer<<endl; } 

..and on , forth.

html

<p>please select how many decimal places show answer :   <select name="decdropdown"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> 

#include <iostream> #include <iomanip>  int main() {      double whatever = 3.13;     // using iomanip header:     std::cout << std::setprecision(100) << std::fixed << whatever << std::endl;  } 

setprecision part of standard namespace, if don't call use std::setprecision , std::fixed or using namespace std; have use std::setprecision , std::fixed instead of setprecision or fixed.

you didn't show header declarations like, judging posted need include header file or use scope resolution operator.


Comments