Forum Moderators: coopster

Message Too Old, No Replies

Getting round numbers

Getting rid of too many digits in dividing

         

henry0

9:22 pm on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$new_width=$_POST['new_width'];
$existing_width=$_POST['existing_width'];
$existing_height=$_POST['existing_height'];

$new_height = ($new_width/$existing_width) * $existing_height;

The above returns too many digits
I need to round it to the closest inferior number if not equal to .5 or to the superior number if above .5

I do not think that the round function can be used or I do not find the correct way to use it.

How can I address my problem?

Regards

Henry

ironik

9:56 pm on Apr 19, 2005 (gmt 0)

10+ Year Member



$new_height = round(($new_width/$existing_width) * $existing_height);

That will round to the nearest whole integer. You can tell it to round to decimal places if you like by adding a number as a second argument to the round() function.

See also ceil() and floor() to control rounding behaviour.

henry0

10:24 pm on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks.
Well as I was afraid I did not read very well the manual :)