How To Get User Friendly Values For Trigonometric Functions?
Solution 1:
Your problem is that java uses radians and not degrees. You have to convert the angle to rad first.
Double rad = degrees /180 * pi;
Solution 2:
First, trigonometric functions do not work with degrees that you are using. You have to send 3.1415926/2 instead of 90. In this case sin
will be much closer to 1 and cos much closer to 0.
But the numbers will still be floating point. If you want to round them for presentation use DecimalFormat
class or String.format()
method.
Solution 3:
Javadoc to the rescue:
Parameters: a - an angle, in radians.
(emphasis mine)
Convert your degrees into radians first. 360 degrees = 2 * pi.
Solution 4:
Take a look at Math.round().
Also, last time I checked, whenever you devide by 0 you do not get infinity. Division by 0 is undefined.
Also, Java uses radians for trigonometric functions, so be sure you are using radians and not degrees or gradians.
Post a Comment for "How To Get User Friendly Values For Trigonometric Functions?"