sandrob57 Posted March 4, 2007 Share Posted March 4, 2007 need some quick variable help. $points $loans_open $loans_max $loans_left Those are the variable we will be working with. basicaly, for every 25 points I want someone to allowed a new loan. So lets say $points = 110 and $loans_open = 1. That means you have 110 points, which allows for 4 loans. Then you 1 current loan open, so you can purchase 3 more. I'm not realy sure how to get the $loans_max variable. Sure I could go $points / 25, but that would give me 4.4 How do I make it so 4.4 rounds down to 4? Thanks. Link to comment Share on other sites More sharing options...
fert Posted March 4, 2007 Share Posted March 4, 2007 http://us3.php.net/manual/en/function.round.php Link to comment Share on other sites More sharing options...
sandrob57 Posted March 4, 2007 Author Share Posted March 4, 2007 never mind Link to comment Share on other sites More sharing options...
doni49 Posted March 4, 2007 Share Posted March 4, 2007 The only problem is that 4.5 to 4.9999999 would round UP. Remember that a number is treated as a string in PHP. Use that to your advantage: $nums = explode(".", $decimal);// <--This will split the decimal number into an array. Element #0 will be the whole number portion and element #1 will be the decimal portion. $wholeNum = $nums[0]; Link to comment Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 floor ($points / 25); Link to comment Share on other sites More sharing options...
roopurt18 Posted March 4, 2007 Share Posted March 4, 2007 Round a float to the nearest integer: $nearest = (int) ($float + .5); No need to call a function. In your case you'd want to do: $loan_max = (int) ($points / 25); Link to comment Share on other sites More sharing options...
chrisuk Posted March 4, 2007 Share Posted March 4, 2007 I would suggest using floor also, as posted by Barand Link to comment Share on other sites More sharing options...
ted_chou12 Posted March 4, 2007 Share Posted March 4, 2007 yeah, i suggest floor() as well. Ted Link to comment Share on other sites More sharing options...
Orio Posted March 4, 2007 Share Posted March 4, 2007 It doesn't really matter- they both will give the same result. You can maybe say that using floor() is more clear, but it doesn't matter. From the other side, I think using casting (using (int)) will be a little bit faster, but even if it is- the difference will be ridiculously small. Orio. Link to comment Share on other sites More sharing options...
Barand Posted March 4, 2007 Share Posted March 4, 2007 I agree and I'm closing this before it becomes a poll Link to comment Share on other sites More sharing options...
Recommended Posts