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
https://forums.phpfreaks.com/topic/133173-solved-round-off-values/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.