SQLite degrees() Function

Savigo
You organize your data. Now organize your savings.
Set savings goals, track your progress, and stay on course.
Get Savigo for iPhone 

Summary: in this tutorial, you will learn how to use the SQLite degrees() function to convert a value in radians to degrees.

Introduction to the SQLite degrees() function #

In SQLite, the degrees() function allows you to convert a value in radians to degrees.

Here’s the syntax of the degrees() function:

degrees(x)

In this syntax

  • x is a value in radians that you want to convert to degrees. It can be an expression or a table column.

The degrees() function returns x converted to degrees. If x is NULL, the degrees() returns NULL.

The degrees() function is a counterpart of the radians() function.

SQLite degrees() function examples #

Let’s take some examples of using the degrees() function.

1) Basic SQLite degrees() function examples #

The following example uses the degrees() function to convert 3 radians to degrees:

SELECT degrees(3) degrees;

Output:

degrees
------------------
171.88733853924697

The following example uses the degrees() function to convert the value of π (pi) radians to degrees:

SELECT degrees(pi()) degrees;

Output:

degrees
-------
180.0

2) Using the degrees() function with table data #

First, create a new table called angles to store angles in radians:

CREATE TABLE angles (
    id INTEGER PRIMARY KEY,
    angle REAL
);

Second, insert rows into the angles table:

INSERT INTO angles (angle) 
VALUES
    (2*PI()),
    (PI()),
    (PI()/2),
    (NULL);

Third, use the degrees() function to convert radians stored in the angles table to degrees:

SELECT
  id,
  angle,
  degrees(angle) AS angle_degrees
FROM
  angles;

Output:

id | angle              | angle_degrees
---+--------------------+--------------
1  | 6.283185307179586  | 360.0
2  | 3.141592653589793  | 180.0
3  | 1.5707963267948966 | 90.0
4  | NULL               | NULL

(4 rows)

Summary #

  • Use the degrees() function to convert a value in radians to degrees.

Was this tutorial helpful?