Jump to content

Round Question


jester626

Recommended Posts

I am pulling info from a MySQL DB.

When I go to use Round like this:

 

echo round($containers,1);

 

It will give me an answer of 5.1 which is mathematically correct. However, I want it to give me an answer to the next highest half (.5) of a container so in this instance I would want the answer of 5.5 not 5.1.  Is there a way to round to the next highest half?

 

Thanks in advance

 

Jester

Link to comment
Share on other sites

If I understand correctly this is what you want:

Input > Output

5.0 > 5.0

5.1 > 5.5

5.2 > 5.5

5.3 > 5.5

5.4 > 5.5

5.5 > 5.5

5.6 > 6

5.7 > 6

5.8 > 6

5.9 > 6

6.0 > 6

 

Than this will do the trick:

<?php
$input = 5.1;
$output = ceil($input * 2) / 2;
echo $output;
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.