# Round and Ceil problem

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I have a problem that I can't seem to solve. I have checked the round,
ceil and floor functions and they don't seem to do what I want.

I have an entry like this

<?php
\$tax = .065;

echo printf ("%.2f", \$ad2day);
?>

That outputs \$111.29, the result of multiplying 104.50x.065 with the
answer rounded to 2 decimal places, then adding in the 104.50 of the

What I want to do is multiply the \$ad2day variable by the \$tax and come
up with a result that will round up any remainder past two decimal
places to the next decmial place. In the example above, the (\$ad2day *
\$tax) comes out to 6.7925. I want to round that up to 2 decimal places
to 6.80 if there is *any* remainder past the two digits. So 6.2401 would
be 6.25, 6.2499 would be 6.25, etc.

Round doesn't seem to do it and ceil only works (i think anyway)
rounding up to whole numbers. What do I need to do to get the result the
way I want it?

Thanks

## Re: Round and Ceil problem

Jack wrote:

[...]

\$x = 6.2501;
\$y = ceil(\$x * 100) / 100; // 6.26

--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com /
== ** ## !!                                                         !! ## ** ==
bypass the spam filter. I will answer all pertinent mails from a valid address.

## Re: Round and Ceil problem

Pedro Graca wrote:

Okay thanks, but that assumes that I already know the value of \$x when
in fact I won't. How can I incorporate that into my original statement of

I really don't want to write a function for each of my 150 entries.

## Re: Round and Ceil problem

JackM wrote:

\$x = \$ad2day * \$tax;
\$y = ceil(\$x * 100) / 100;

Replacing \$y:

\$x = \$ad2day * \$tax;
\$ad2day = round((ceil(\$x * 100) / 100) + \$ad2day, 2);
/*          \$y = ceil(\$x * 100) / 100; */

Replacing \$x

\$ad2day = round((ceil((\$ad2day * \$tax) * 100) / 100) + \$ad2day, 2);
/*                \$x = \$ad2day * \$tax; */

--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com /
== ** ## !!                                                         !! ## ** ==
bypass the spam filter. I will answer all pertinent mails from a valid address.

## Re: Round and Ceil problem

Pedro Graca wrote:

Thanks Pedro, the replacing \$x option is the one I was seeking. Works
like a charm. Much obliged for the help.