Jump to content

round down


sandrob57

Recommended Posts

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

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

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

Guest
This topic is now 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.