Make decimal value decrease or increase [duplicate] - php

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;

Related

Round number down the to the nearest hundredth using php [duplicate]

This question already has answers here:
How to round up a number to nearest 10?
(16 answers)
Closed 4 years ago.
I'm probably not looking hard enough but the common question about php rounding is rounding up, not down.
For example I am trying round this..
<?php $roundDown = 768; ?>
Down to..
<?php var_dump($roundDown) /* 700 */ ?>
Whats the simplest method to do this, or is it because the number is closer to 800 that it's not technically rounding?
Whats the function that I need to do this if it's not rounding?
A little point in the right direction would be much appreciated.
You can try ceil() and floor() function.
echo floor(768 / 100) * 100; // Output:700
echo ceil(768 / 100) * 100; // Output:800

Php change 5.0E-5 into 0.00000050 [duplicate]

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

What will be the output 012/2 in PHP? [duplicate]

This question already has answers here:
int variable with leading zero?
(5 answers)
Closed 5 years ago.
What will be the output of this expression ?
$a = 012;
$b = $a / 2;
var_dump($b);
I got the answer (int) 5 Please anyone suggest me how this is calculate ?
When you use a leading 0 in 012, you're actually using octal notation. That means, that this is 12 number but as an octal number.
So012 is actually 8+2, which is 10 as a decimal number.

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

Computing limits in PHP [duplicate]

This question already has answers here:
Is there something that's larger than any numbers in PHP?
(9 answers)
Closed 8 years ago.
I want to compute n^(2/3) as n approaches infinity in PHP.
What I tried:
$n = "INF";
echo pow($n, (2/3));
Desired result:
INF
Actual result:
0
Any suggestions? How to compute limits in PHP?
UPDATE:
OK, first problem solved - I just needed to remove the quotation mark.
But is this actually the way to calculate a limit? Is it interpreted as a limit?
You're passing in the string "INF" into the exponential expression, which isn't valid. Try passing in just POW:
$n = INF;
echo pow($n, (2/3));
// INF

Categories