Need to input to certain amount of places

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
afaik
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 19
Joined: Mon Jun 16, 2008 11:13 pm

Need to input to certain amount of places

Post 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?
Post Reply