Devansh Sharma
Devansh Sharma

Reputation: 144

Expressing Radians C++

How would I convert degrees to radians exactly. Rather than showing 0.785398 I want the program to show pi/4.

I am currently using this script to convert degrees into radians.

cout << angle * M_PI / 180.0 << " radians";

Upvotes: 1

Views: 4069

Answers (1)

Jarod42
Jarod42

Reputation: 218323

You might do

 std::cout << angle / 180.0 << " pi radians";

Which will print

 0.25 pi radians

You might be interested by how-to-convert-floats-to-human-readable-fractions to convert 0.25 into 1/4.

Upvotes: 1

Related Questions