You are on page 1of 2

signup login tour help

xDismiss

JointheStackOverflowCommunity

Stack Overflow is a community of 6.6 million


programmers, just like you, helping each other.
Join them it only takes a minute:

Signup

c#mathcosdifferentvaluesfromcalculator

Iamtryingtodoaprecisiontypeofprogramwhereiencounteredvaluestherewerewrongandhavebeenabletopinpointtheproblemarea.The
Math.cosvaluesdifferfromthecalculatorvaluesandhowcanicorrectthisforinstance

Math.Cos(28.545742)

givesthevalue0.963394351754924butonallothercalculatorsitgivesmeacorrectvalueof0.8784358937whichisperfectsinceitcompletes
theexpectedprogramoutput.HowcanIgetMath.CostogivemetheanswersIwant?andthisismyfirsttimemessingwithC#mathfunctions.

c# math

askedJan2'14at21:43
user1591668
537 1 6 21

4 Iwouldguessthat C# isworkinginradians,but"allothercalculators"areworkingindegrees.
TeepeemmJan2'14at21:46

1 Youneedtospecifytheangleinradians,notdegrees.BlorgbeardJan2'14at21:46

Theothercommentsarecorrect... google.com/#q=cosine+28.545742alsoshowsthe0.96..answer,using
radians.EricKingJan2'14at21:48

Thankseveryonethatsolvedtheanswer user1591668 Jan2'14at22:02

3Answers

Math.Cos() isusingradianswhileyourcalculatorisusingdegrees.Asimplewaytoconvertfrom
degreestoradiansisdegrees*(pi/180).

Incode:

Math.Cos(28.545742*(Math.PI/180))

editedJan2'14at21:52 answeredJan2'14at21:48
connor
35.5k 16 98 120

Youneedtospecifytheangleinradians,notdegrees.

Thereare 2*pi radiansinacircle,and360degrees.Sotoconvertdegreestoradians,divideby


360andmultiplyby 2*pi (simplified:multiplyby pi/180 ):

Math.Cos(28.545742*Math.PI/180f)

Willgiveyouthecorrectanswer.

answeredJan2'14at21:49
Blorgbeard
62.6k 31 160 222

Math.Cos functiontakesvaluesinradians.

HereisthedetailedexplanationonMSDNsiteaboutthefunction.

editedJan2'14at22:27 answeredJan2'14at21:54
Rakhi
134 4

EverylanguagethatIknowofFORTRAN,C,C++,Java,C#,Python,Javascriptallexpectanglesin
radians.duffymoJan2'14at22:09

You might also like