How to print 0.00009 and lower number [duplicate] - php

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

Related

PHP Division return Floating Point that contains E issue [duplicate]

This question already has answers here:
Why is PHP printing my number in scientific notation, when I specified it as .000021?
(7 answers)
Closed 3 years ago.
I'm trying to do division in my code, here is mine:
$total = $dateRange / $value; // 2 / 10000000
it give me result 2.0E-7 instead of 0.0000002. Isn't it a floating point?
I've tried to use convert to string or json_decode it's still give me same result, and number_format((float) $result, 6, '.', '') gives me
0.000000
You can use -
echo rtrim(rtrim(sprintf('%.8F', $result), '0'), ".");

How to set a decimal value up to 8 decimal places in php [duplicate]

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);

PHP numbers, hide largenumbers [duplicate]

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);

Remove the "E" in a number format for very small numbers [duplicate]

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

shorten a long number with php [duplicate]

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);

Categories