precision on scientific notation

i wanna change the precision of a number in scientific notation. e.g.: i have 3.459560456e-3 and i want a precision p=3, that is 3.46e-3... if i multiply by pow(10,3), then round and divide,the answer would be 0.001...

is maybe ios_base::precision the solution?
i don't know how to use it ... how can i declare an object that kind? i want it to deal with variables, not a std output..

any hints welcome!
Are you talking about displaying the number to a certain number of significant digits or are you talking about storing the number rounded number?
cout.precision(?) sets a floating point format to display (?) digits. The original precision is rounded as required. I suspect that cout.width(7) would be appropriate if needed.
YEAH, buffbill, i want to do exactly that ".precision()", but i do not want to display it, i want to store it in a variable. so kbw, i am talking about storing ;)

i would like to declare some variable <roundNum> so i could round my number <num> up to <x> significative digits doing sthg like roundNum.precision(x)

???
Did it help?
Last edited on
Topic archived. No new replies allowed.