Friday, December 20, 2024

MySQL DEGREES() Function

 In MySQL, the DEGREES() function is used to convert an angle from radians to degrees. It takes a numeric value in radians as an argument and returns the equivalent angle in degrees.

Syntax:

DEGREES(radians)

Parameters:

  • radians: The angle value in radians that you want to convert to degrees.

Return Value:

  • The function returns the angle in degrees as a floating-point number.

Example:

SELECT DEGREES(PI());  -- Converts PI radians to degrees

This will return:

+----------------------+
| DEGREES(PI())        |
+----------------------+
| 180                  |
+----------------------+

In this example:

  • PI() returns the value of π (pi) in radians.
  • DEGREES(PI()) converts that value to degrees (π radians = 180 degrees).

More Examples:

  1. Convert 1 radian to degrees:
SELECT DEGREES(1);

This will return approximately:

+-----------------+
| DEGREES(1)      |
+-----------------+
| 57.29577951308232 |
+-----------------+
  1. Using DEGREES() with a calculation:
SELECT DEGREES(SIN(PI() / 4));

This will return the result of sin(π/4) converted into degrees.

Notes:

  • To convert degrees back to radians, you can use the RADIANS() function in MySQL.

No comments:

Post a Comment