Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP errror in cos() function

In an exercise I did :

<?php
$initial = '555';
$a = octdec($initial);
echo $a . "\n";

$b = deg2rad($a) . "\n";
echo $b;

$c = cos($b). "\n"; *(line 9)*
echo $c;

and it does show the correct answer, as well as an error:

365
6.3704517697793
0.99619469809175
PHP Notice:  A non well formed numeric value encountered in /home/ccuser/workspace/hg2pmf/index.php on line 9

if I change line 9 with : $c = cos(6.3704517697793). "\n"; the message of error disappear. Why can’t I use the $ inside the cos() when in deg2rad() works perfectly?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem is that on this line…

$b = deg2rad($a) . "\n";

You are adding the new line onto the end of the calculated value.

So remove it and your value will be the number you expect…

$b = deg2rad($a);

As a help, I use

declare(strict_types=1);

and I get the error…

Fatal error: Uncaught TypeError: cos(): Argument #1 ($num) must be of
type float, string given in
which shows how it’s changed the value from a number to a string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading