PHP rad2deg() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In PHP, rad2deg() converts an angle from radians to degrees.

Math functions like sin() and cos() work in radians, but people usually think in degrees. rad2deg() translates the angle for you.

Syntax

Call rad2deg() with the values you need. Start with this line.

PHP
$degrees = rad2deg(M_PI);
CallWhat it does
rad2deg(M_PI)Returns 180.
rad2deg(M_PI_2)Returns 90.
rad2deg(1)Returns about 57.2958.

A full circle is 2 x pi radians, which equals 360 degrees. The reverse function is deg2rad().

Library declarations
PHP
rad2deg(float $num): float

Parameters

ParameterDescription
numRequired. The angle in radians.

Return Value

Return ValueDescription
floatThe angle converted to degrees.

PHP Examples

Example 1 — Common Angles

Convert well-known radian values to degrees.

PHP
<?php
echo rad2deg(M_PI), PHP_EOL;
echo rad2deg(M_PI_2), PHP_EOL;
echo rad2deg(M_PI_4), PHP_EOL;

How It Works

  1. M_PI is half a circle, which is 180 degrees.
  2. M_PI_2 is a quarter of a circle, which is 90 degrees.
  3. M_PI_4 is an eighth of a circle, which is 45 degrees.
  4. PHP prints whole floats without decimals.

Example 2 — Zero, Negative, and Full Circle

rad2deg() works with zero, negative angles, and angles larger than a circle.

PHP
<?php
echo rad2deg(0), PHP_EOL;
echo rad2deg(-M_PI), PHP_EOL;
echo rad2deg(2 * M_PI), PHP_EOL;
echo round(rad2deg(1), 2), PHP_EOL;

How It Works

  1. Zero radians is zero degrees.
  2. A negative angle gives a negative result, so -M_PI becomes -180.
  3. 2 x M_PI is one full turn, which is 360 degrees.
  4. One radian is about 57.2958 degrees, rounded here to 57.3.

Example 3 — Convert the Result of atan()

Inverse trigonometry functions return radians. Use rad2deg() to see degrees.

PHP
<?php
$angle = atan(1);

echo "Radians: ", round($angle, 4), PHP_EOL;
echo "Degrees: ", rad2deg($angle), PHP_EOL;

How It Works

  1. atan(1) asks which angle has a tangent of 1.
  2. The answer is about 0.7854 radians.
  3. rad2deg() converts that radian value into degrees.
  4. The final result is 45 degrees.

Frequently Asked Questions

rad2deg() converts an angle from radians to degrees.
Use deg2rad(). For example, deg2rad(180) returns pi.
PHP trigonometry functions use radians. If you have degrees, convert them with deg2rad() first.
Degrees = radians x 180 / pi. For example, pi radians equals 180 degrees.
Yes. It does not wrap the angle. Use fmod($degrees, 360) if you need a value between 0 and 360.

Next: round()

round() rounds a number to the nearest whole number or chosen decimal places.

round() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful