PHP, Prevent the removal of leading zeros

I have an array of numbers from 5 to 6.4, but the numbers are related to feet and inches and I use them to calculate.

When I come to use 5.10, it removes zero, and I get the same result as 5.1.

In any case, to prevent the removal of PHP 0. I assume that it performs some sort of drop by default.

Thanks in advance

+3
source share
7 answers

If you mean 5 feet and 10 inches, you cannot imagine that with an integer (or swimming) - as you can see, you will encounter serious problems in this way.

, ( , ). . Google , 5,8 == 69,6 , 5 8 (== 68 ). (float) 5.10 === (float) 5.1 === (float) 5.100000 ( ).

, int - (IIRC, 1 = 12 , 5 1 = 5,083 , ).

, . Zend_Measure; PHP, , , US/Imperial.

EDIT: , , - . 5'10 "== (5 * 12) + 10 == 70 , , .

+9

, , , ( ), , . , , .

+5

+3
0

, Settype

settype($bar, "string");  // $bar is now "1" (string)

. 0 5.10 ?

comp. printf/sprintf , 2 , , .

0

You can try using printf

$a = 5.10;

echo $a;            // prints 5.1

printf("%.2f",$a);  // prints 5.10
0
source

These values ​​are converted to float implicitly somewhere in your code. You need to find this line and rewrite it to save the type of the line. Do you use these values ​​in mathematical expressions, for example?

0
source

Source: https://habr.com/ru/post/1730884/


All Articles