This question already has answers here:
PHP int typecasting generating wrong value [closed]
(3 answers)
Closed 9 years ago.
I am absolutely new in php. I got an question from somewhere. and the question was what will be the output of the following code?
<?php
echo 0050;
?>
The result is showing 40. My question is why its showing 40 and how?? I need details information about this. what is 0050?
050 is an octal (base 8) literal for 40 (base 10).
http://php.net/manual/en/language.types.integer.php
0050 is a value in octal which is a base 8 number system. when printed the number is first converted to a decimal representation and printed.
Related
This question already has answers here:
Rounding up to the second decimal place [duplicate]
(2 answers)
PHP: Round a number upto 2 decimal places and if the number is a whole number then add trailing zeros
(4 answers)
Closed 2 years ago.
Thank you if you help me to solve this.
I need this round up with 2 decimal
<? echo round(ceil((0.55*100))/100,2); // output 0.56 ?>
I want this
0.050 -> 0.05
0.051 -> 0.06
0.055 -> 0.06
0.059 -> 0.06
0.060 -> 0.06
Thank you!
This question already has answers here:
Use numbers starting with 0 in a variable in php
(3 answers)
Weird output, when number starts with 0
(1 answer)
Closed 5 years ago.
Why are negative numbers starting with zero giving different output?
<?php
echo -0222;
Output: -146 Why?
Ex: https://glot.io/snippets/eprnnw04bd
This question already has answers here:
How to strip trailing zeros in PHP
(15 answers)
Show a number to two decimal places
(25 answers)
Closed 7 years ago.
This questions is kinda confusing, but here I am telling you the exact problem I have.
In database I have a column with datatype double(10,6), means the value can have upto 6 decimals depending on each user.
Some user have a value 5.22 say in this column.
Now when I echo this value in php, I want it to show 5.22 or 7.256 not 5.220000 or 7.256000.
I hope its clear.
Thanks.
This question already has answers here:
How to fastest count the number of set bits in php?
(6 answers)
Closed 8 years ago.
If i have 2 binary number representation: 127 and 128. How can i calculate that 127 have 7 bits "ON" and 128 have only 1 bit "ON"?
I did it like the following, but i think there's probably a better way (with math):
strlen(str_replace('0','',decbin(127))); // 7
strlen(str_replace('0','',decbin(128))); // 1
It looks like what you want is a population count. The Wikipedia reference has some code, and for problems like this I always check Bit Twiddling Hacks which is a great reference.
There are asm instructions for this on some machines, and both gcc and MSVC have compiler builtins.
For other languages, see: Population Count on RosettaCode
This question already has answers here:
PHP float/double stored as MySQL DECIMAL
(2 answers)
Closed 8 years ago.
I have a table with a DECIMAL(10,6) column. I have a string representation of a float (e.g. 35.3123122). I am using php to insert the value. I used floatval($string) to insert and it did not work. I also tried to insert the string itself with no success. Do I need to format the float value exactly to match the 10,6 criteria. If so, How can I do this?
Thanks
Not sure if this is your problem, but the value of "35.3123122" has 7 digits after the decimal point. DECIMAL(10,6) is 10 digits in total with a maximum of 6 digits past the decimal point.