Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Members have full access to the forums. Advertisements are removed for registered users.

# Thread: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

1. ## Confusion with Math.toDegrees() and Math.toRadians(). Please help.

Dear administrators and members,

A greeting of peace.

I hope everyone is in good health upon reading this thread.

I am currently working on a simple program that uses trigonometric laws like sine laws. I first try to write this simple codes first:

```double angle = 60;
System.out.println( Math.sin(Math.toDegrees(angle) );```

Then the output is: 0.7475(something)

I wonder why the output is 0.7475(something)? BUT, when I tried pressing sin 60 on my scientific calculator (in degrees mode as usual) the answer is 0.8660(something).

Then later, I tried to use toRadians() method in Math class:

```double angle = 60;
System.out.println( Math.sin(Math.toRadians(angle) );```

Then that is the time I got the 0.8660 (something) answer.

I am just a little confused. My scientific calculator is in degrees mode, that is why I am expecting the same result if I will use the toDegrees() method, but why it did not?

Please enlighten me. Did I miss something?

Respectfully Yours,

MarkSquall

2. ## Re: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

Hi,

for Math.sin(doulbe a), a is an angle, in radians (pls refer to in API document), that's why sin(Math.toRadians(angle)) works.

3. ## Re: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

one more thing, following words are from API document, FYI.
about toDegrees, "The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0. "

4. ## Re: Confusion with Math.toDegrees() and Math.toRadians(). Please help.

Dear Ms. ivy,

I already read the Java API documentation, and it's a great help for some useful definition. BUT, I just wondered why toRadians() is the one gave me the correct answer (as the one in my scientific calculator) than toDegrees() .

Is it not if I press sin 60 in my scientific calculator, 60 is already (or "converted") in degrees (since my calculator is in DEG mode)?

But anyway, a million thank you and more power.

Warm regards,

MarkSquall