Jump to content

Help With Round()


Adam03520

Recommended Posts

Hi, i need help with the round function to round a number up and another down to the next 10..

 

Example:

 

First number: 32

Second number: 32

 

I want the first number to be rounded down to the next 10 so the first number after rounded would become 30..

And the second number wants to be rounded up to the next 10 so the second number would be 40 (after rounded)..

 

I have tryed the ceil() function to round it up to the next 10 but it does not work..

 

Thank you.

 

Link to comment
Share on other sites

Divide by ten, then use floor or ceil (depending on if you want up or down). Then multiply by 10.

 

Well the problem with ceil and floor is they do nothing to the number.. Here is how i tryed it..

 

I put this code just to test to see if it did make the number go up / down

<?php echo "Ceil Two Is: ".ceil(2)."<br />Floor Two Is: ".floor(2); ?>

 

And the out come from that was this..

 

Ceil Two Is: 2

Floor Two Is: 2

 

-----------------------------------------

 

Wait, sorry i just been on php.net and it says on there it rounds it to the whole number, when this is not doing anything because it is an whole number.. My bad >_>

Link to comment
Share on other sites

Now try exactly what jesirose suggested with your examples.  It works.

 

If you example isn't representative of what you're really trying to do, then provide a more complete explanation of the problem.

 

Ok, here is the code...

 

<?php
$level = 32;

$num = $level;
$num = $num / 10;
$num_floor = floor($num);
$num_floor = $num_floor * 10;

$num2 = $level;
$num2 = $num2 / 10;
$num_ceil = ceil($num2);
$num_ceil = $num_ceil * 10;

echo $num_floor.":".$num_ceil;

?>

 

See the $level string is the number and that number can be any number... What i need the $higher string to echo is the level rounded down to the next 10 and the other rounded up to the next 9.. Example:

 

The level is: 32

The out come from this would be 30:39

 

Another:

 

The level is: 47

The out come from this would be 40:49

 

You see what i mean?

Link to comment
Share on other sites

Adam, before you said you wanted it rounded to even 10s, now you say to the next 9...you're not being clear.

 

Yes, because i didnt think you would really understand, and with it been to the 10s it would be easyer for you and then i could just take away one from the value.

Link to comment
Share on other sites

That's rich.

If you want help with something, you should ask for what you want help with. If you assume we won't understand why would we be able to help in the first place?

 

You should divide by 10, use floor, multiply by 10. That is your 30. then ADD 9 and that is your 39.

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.