Page 1 of 1

Need to input to certain amount of places

Posted: Sun Jun 29, 2008 1:47 pm
by afaik
I need to find the cosine of a number. The problem is, when I use the cos function, I need to convert from degrees to radians and the number I receive isn't necessarily accurate when you do something like

cos(90 * (pi/180) )

It will give you .32679e-006 which is: .00000032679.

I only need the first few decimal places since the answer is supposed to be exactly zero.

I know I can output

cout << fixed << setprecision (3) << cos(90 * (pi/180)) << endl;

to whatever amount of places I need. In this case 4 should be ok without losing accuracy. Any ideas?