This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 9 years ago.
how can i shorten a long number with php ? So a number like 0.3483748937847832 would become 0.34
Please search stackoverflow first - from PHP: show a number to 2 decimal places
number_format()
return number_format((float)$number, 2, '.', '');
https://stackoverflow.com/a/4483561/689579
or
$padded = sprintf('%0.2f', $unpadded); // 520 -> 520.00
https://stackoverflow.com/a/4483715/689579
Use round
echo round($number,2);
Related
This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 3 years ago.
I want to show amount of bitcoins up to 8 decimal points. I have stored the value in Satoshi but when I try to convert the satoshi to BTC by dividing the satoshi value with 100000000 I am getting invalid result. here is my code.
$res = 3535/100000000;
echo $res;
the output of the above code is 3.535E-5 isntead 0.00003535.
please tell me the proper solution.
echo number_format(3535/100000000, 8);
Where 8 is the count of 0's. For example for 3535/1000000000 you need to write
echo number_format(3535.0/1000000000, 9);
This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 6 years ago.
Hi i have a one question.
I get this numbers in result: 1.1115628363
I want to show the first three numbers example: 1.11
But i dont know how to do this. Thank you for your help
$number = 1.1115628363;
$formated_number = number_format($number, 2, '.', '');
You can use substr function for that.
Try below code :
$test = 1.1115628363;
echo substr($test, 0, 4);
This question already has answers here:
split string after x characters
(3 answers)
Closed 7 months ago.
Using PHP...
If I have a number, for example, 0901, how can I then get 2 separate variables?
The first containing "09" and the second "01".
Thanks!
Using str_split. You can divide in half.
$number = "0901";
$arr = str_split($number, strlen($number)/2);
print $arr[0];
print $arr[1];
This question already has answers here:
php- floating point number shown in exponential form
(4 answers)
Closed 7 years ago.
When I echo this:
round($number* 100, 12)
I get output numbers that look like this:
6.6936406E-5
How do I remove the "E" and show the numbers as they are, i.e. like this:
0.0000066936406
use number_format.
$number = number_format($number, 12, '.', '');
http://php.net/number_format
This question already has answers here:
Convert a big integer to a full string in PHP
(4 answers)
Closed 9 years ago.
Trying to echo 0.00009 number gives me 9.0E-5 tryed to do
echo number_format($number);
it echoes 0, maybe someone could explain me how to print my number and even lower ones.
You probably want something like this...
number_format($number, 5, '.', '');
That should give you the number to 5 decimal places, using . for the decimal (English format).
Reference: http://php.net/manual/en/function.number-format.php