Jump to content

[SOLVED] Round Off Values


keyurshah

Recommended Posts

Hello my freaky family members. A small help is needed.

 

I get a set of prices whenever a user selects a vehicle make. Say a user selected a make called Ford, then I get the price set as 'From' price is 456980 and the 'To' price is 678698.

 

I need to display the 'From' price at the lowest, meaning if it is 456980 then it should show 400000 and the 'To' price at the highest, meaning if it is 678698 then it should show 700000. Can anyone help?

 

I have tried using round() but to no avail. Using ceil() and floor() are probably immaterial as my 'From' and 'To' values are not in decimals.

 

Any help will be highly appreciated.

 

Thanks in advance!

Link to comment
Share on other sites

Don't no of any functions off the top of my head. But try these two out:

 

function whole_ceil($n){
$divide = (int) "1".str_repeat("0", strlen($n)-1);
return ceil($n / $divide) * $divide;
}

function whole_floor($n){
$divide = (int) "1".str_repeat("0", strlen($n)-1);
return floor($n / $divide) * $divide;
}

 

Then to call:

 

$from = whole_floor(456980); //Should give 400000

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.