Php change 5.0E-5 into 0.00000050 [duplicate] - php

This question already has answers here:
Display float value w/o scientific notation
(4 answers)
Closed 5 years ago.
I am working on my site about bitcoins. And people can have balances there. I am btw working in php. In my $user_data["balance"] the value is 50. And I want that to get converted by php into 0.00000050. So I tried this:
$balance = $user_data["balance"] / 1000000;
But what I get from it, is this: 5.0E-5. How to change it into 0.00000050?
I would be really thankfull if somebody would help me!

Use number_format to get results with 8 decimals.
Example-
$balance = number_format($user_data["balance"] / 1000000,8,".","");
echo $balance; //output will 0.00005000
But if you want 0.00000050 then divide it by 100000000
Example
$balance = number_format($user_data["balance"] / 100000000,8,".","");
echo $balance; //output will 0.00000050

Related

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

Make decimal value decrease or increase [duplicate]

This question already has answers here:
Round to max thousand, hundred etc in PHP
(5 answers)
Closed 5 years ago.
I have a questions to decrease or increase decimal value in my PHP. For example I have 2573000.00 I want to make it 2500000.00. I have tried to use round() but not give me best answer. How to do that ?
Thank you.
Try this:
$a = 2573000.00;
$b = (int)($a / 100000) * 100000;
echo $b;

php Rounding up numbers (3628 > 3630) [duplicate]

This question already has answers here:
How to round up a number to nearest 10?
(16 answers)
Closed 6 years ago.
After converting currencies I end up with the numbers below:
3628, 5987 and 2359.
I'd like to round them up so they would appear as 3630, 5990 and 2360.
What is the best approach to accomplish this?
My idea of doing this is adding a 0. in front of the number to achieve 0.3628, then using round(0.3628, 3) so that I would get 0.363 and then finally id have to remove 0. and add another zero at the end to achieve 0.3630.
There must be a better way to do it.
Like so:
echo ceil(5987 / 10) * 10;
outputs 5990

PHP format for Lakh and Crore [duplicate]

This question already has answers here:
Is there any PHP function to convert number to currency with thousands separators?
(2 answers)
Closed 7 years ago.
Want to format number in php like 1,00,00,00,000. I am trying the following function
number_format($var['count'])
but it is giving me following answer 1,000,000,000
Thanks and Regards
You can try this, to do additional formatting read through PHP's documentation: PHP.NET - Money Format
$dollar = 6000000000;
setlocale(LC_MONETARY, 'en_IN');
echo $dollar = money_format('%!i', $dollar);
Output:
6,00,00,00,000.00
Try this
$number = 123554646;
setlocale(LC_MONETARY,"en_IN");
echo money_format("The price is %i", $number);
Output
The price is INR 12,35,54,646.00
Check Phpfiddle Preview

How to do math with a string? [duplicate]

This question already has answers here:
How do I convert a string to a number in PHP?
(35 answers)
Closed 7 years ago.
So lets show an example here shall we?
Let's say I have 2 strings that are like this....
$math1 = "+300";
$math2 = "-125";
So obviously the answer would have to be +175 but how do I actually do the math while the input is a string.
I can't simply do
$math1 - $math2
Because it'd have to figure out if it is a + or a -, so how can this exactly be done?
You can use intval to get the integer value of a variable, and then you can do basic math operations.
<?php
$math1 = intval("+300");
$math2 = intval("-125");
echo $math1 - $math2;
?>
intval($math1) + intval($math2);
Can be:
$result = abs($math1) - abs($math2);

Categories