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

How to use/assign negative floats in PHP

It seems soo trivial but I’m struggling with it, please help!

Basically I need to assign negative float values like this:

$celsius= −53.9; 

but this format is not working ( throws error: )

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

syntax error, unexpected ‘.9’ (T_DNUMBER)

I tried to cast it float ( float(−53.9), (float)−53.9 ), that’s not working either ( it gives back 0 as a result ). I’ve also tried to create it as a string $celsius= '−53.9'; and then cast it to float later on but that’s also not working. I think I’m missing some basic knowledge here so Any help is greatly appreciated, Thank you in advance!

>Solution :

As mentioned in my comment, your minus sign isn’t the correct one.

Given the following file contents (depending on your font you can see the difference already)

$celsius= −53.9;

$celsius= -53.9;

Have a look at the hexdump:

00000000  24 63 65 6c 73 69 75 73  3d 20 e2 88 92 35 33 2e  |$celsius= ...53.|
00000010  39 3b 0a 0a 24 63 65 6c  73 69 75 73 3d 20 2d 35  |9;..$celsius= -5|
00000020  33 2e 39 3b 0a                                    |3.9;.|
00000025

In the first assignment, the minus is shown as three dots and encoded as e2 88 92, in the second as 2d

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