3
case R.id.bTanx:
        temp=(float) (number/0.0174532925);
        num=Math.tan(temp);
        display.setText("Your Result is   " + num);

Guys I'm not able to get "Your Result is 1" when number = 45 ,by this code.Please help. As tan(45)=1 in degrees.i have converted it.but no desired result.

6
  • 1
    Where does Javascript or Eclipse come into this? You should look into the way you're converting degrees to radians, too... (hint: examine temp, and see whether it's what you expect) Commented Dec 19, 2013 at 10:51
  • Use multiply instead of division. Commented Dec 19, 2013 at 10:53
  • 6
    Why is people downvoting this? Can't newbies join the community? Commented Dec 19, 2013 at 10:53
  • use number*0.0174532925 and not number/0.0174532925 Commented Dec 19, 2013 at 10:54
  • @RamonBoza I agree, I think the OP establishes a valid question, provides the information needed to solve it and demonstrates their attempt. It would have been nice to see a more complete example, however it does appear they are new. Commented Dec 19, 2013 at 10:55

1 Answer 1

4

To convert degrees to radian you first need to convert the degrees to a factor (of the circles circumference) by dividing by 360 degrees. Next you multiply by 2PI rad (which is the circumference of a 'unit circle').

When looking at the units you do this: degrees / degrees * radians = radians

So where you divide by 0.017 (2*PI / 360), you need to multiply instead:

temp = (float) (number * 0.0174532925);

Furthermore it is nicer (more clear) if you do not use 'magic numbers' and add comments (so people know what you are doing):

// Convert to rad
temp = (float) (number * 2 * Math.PI / 360);

And/or even use the available Java functionality:

// Convert to rad
temp = Math.toRadians(number);
Sign up to request clarification or add additional context in comments.

2 Comments

thankyou but this wont convert the number to radians. we convert degree to radians by radian= (degree )/ .0174
I added an explanation why you need to multiply instead of divide to my answer. Hopefully it will make it more clear what is going wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.