how to deal with more precise values?

Hello,
i started working on variables that are more precise i.e. 3.25456987895787 * 0.0000059988565
But i cant find find any way to do calculation on this much precise value, i tried
cout.setf(ios_base::fixed,ios_base::floatfield);
but its kinda messed up!
Can anyone help through this?
closed account (1yR4jE8b)
setf will only work on what is displayed, but not the actual values themselves. If you need more precision than what standard double and long long values offer you could try GNU GMP. It's made for working with numbers of arbitrary precision.

http://gmplib.org/
i have to submit my code as assignment so i cant use another libraries!!!
i have to use default libraries. Can you tell me how to do so using long double !?
It's not entirely clear whether you're concerned with the precision of your variables and calculations or with the displayed precision of your output. In the example you gave, both of those numbers can be represented by a double, though you will lose some accuracy on the result. To retain some of it, you could declare the variables & result to be long doubles. Though you need to really take a good look at your problem to see if that is warranted.

If the question is the displayed precision, then look at setprecision(): http://www.cplusplus.com/reference/iostream/manipulators/setprecision/
i want to set precision by myself.
eg
1
2
3
4
5
6
7
8
i=0.000094;
j=56000;
k=i+j;
cout.precision(6);
cout<<fixed<<k;

gives : 
k=56000.000094;


but lets say, i want to use i=0.00009 instead of i=0.000094 (upto 5 decimals) for calculation and i dont want to declare another variable for that. So how to do that?

can i switch precision for calculation? How?
Last edited on
Topic archived. No new replies allowed.