PHP round three decimal places up with problem [duplicate] - php

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!

Related

Why are negative numbers starting with zero giving different output? [duplicate]

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

Showing decimal values until its not 0 [duplicate]

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.

If no decimals, add default ones [duplicate]

This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 8 years ago.
Having the following decimal numbers:
47.44
180.11
340
12.39
25
I was wondering, how can I add a default .00 to those numbers, that have no decimals?
You can use number_format() like that:
number_format($number, 2);
It'll always return number with two decimals. Also it'll separate thousands with ',' (if you don't want that, add '' as fourth parameter).

what is 0050 and why echo 0050 result 40 [duplicate]

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.

Round to the nearest tenth? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Round up to the nearest 50,000 in PHP
I have this, 52.52 and I want it to become 52.5. How would I do that in PHP? I tried round() but did not work. Thanks.
round($num, 1);
should round $num to the nearest tenth (the second argument specifies the precision, or the number of digits after the decimal it should round to)
Try
$x = number_format('52.52', 1)
Documentation is here

Categories