setprecision of a specific value

Is there a way to define a number of digits for a number that is not an output?
For example, I want to output a result of pi*2*10 for pi = 3.1415926535 which would be 62.83185307. I am however only able to setprecision for the output of equasion itself and that does not give the wanted result.

closed account (48T7M4Gy)
A simple example of a way to truncate your answer
1
2
double x= 1.234;
std::cout << int(x*10)/10.0;


1.2

What exactly are you aiming to achieve here?

One thing you could do is to convert the floating-point value to a string. (probably using a stringstream to get the required 11 significant digits (since the value for pi had 11 significant digits).

But if you want to do any sort of mathematical calculation with the number, you'd have to convert it back from the string to a floating-point type, which will probably give back the same number as before, or possibly a less accurate value, since the convert to string discarded some information.
Last edited on
Topic archived. No new replies allowed.