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);
Related
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:
Formatting a number with leading zeros in PHP [duplicate]
(11 answers)
Adding leading 0 in php
(3 answers)
Closed 8 years ago.
In PHP, I need to display a big 5 digit, graphical counter from a number fetched from a database. Examples:
If number = 1, counter should display 00001
If number = 15, counter should display 00015
if number = 999, counter should display 00999
What's the easiest way to achieve this?
You could use str_pad:
$output = str_pad ($input, 5, '0', STR_PAD_LEFT);
The versatile printf or sprintf for the value 1 as 00001:
printf('%05d', 1);
printf formats have a zero-padding option:
printf("%05d", $number);
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
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);