crynaldo madrid
crynaldo madrid

Reputation: 648

How get original price from rounded value in php?

I have a code like this $new_amount = round(($old_amount/53),2);

amount may be 1,2, ...,10000;

How get exact $old_amount from $new_amount; Now i tried to use

$old_amount = ceil($new_amount);` AND `$old_amount = floor($new_amount);

but not working properly; please help me;

Upvotes: 0

Views: 111

Answers (2)

Muatik
Muatik

Reputation: 4171

If you need the exact amount, don't change the $old_amount while creating $new_amount. So you can use $old_amount later.

There is no way to back. Both Ceil() and floor() functions can't give you what you want.

Upvotes: 0

Jon Taylor
Jon Taylor

Reputation: 7905

You can't, once you round a value you get rid of the extra precision. This precision is lost. However, the old value is still stored in the $old_amount variable.

Upvotes: 3

Related Questions