php-general Digest 16 Jan 2012 22:52:04 -0000 Issue 7652

Topics (messages 316301 through 316308):

Re: Numeric help needed
        316301 by: Jason Pruim
        316302 by: Chris Payne
        316303 by: Simon J Welsh
        316304 by: Curtis Maurand
        316305 by: Robert Williams
        316306 by: Curtis Maurand

Thank you all for your help
        316307 by: Chris Payne

sessions and expirations and isolations
        316308 by: Haluk Karamete

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---

Sent from my iPhone

On Jan 15, 2012, at 8:25 PM, "Christopher J Payne" <oxygene...@gmail.com> wrote:

> Hi everyone,
> 
> 
> 
> I am having a hard time with a numerical problem.
> 
> 
> 
> I need to round some numbers up and I've tried $round($number) and it
> doesn't work so I'm misunderstanding something.
> 
> 
> 
> For example, if a user inputs 685000 I need it to round up to 690000 or if
> they input 149560 I need it to round up to 150000.  What is the correct way
> to do this as everything I have tried doesn't seem to affect the user
> inputted figure at all.
> 
> 
> 
> Anyway help would REALLY be appreciated, I'm sure it's really simple but for
> the life of me I'm stumped on why it's not working.
> 

Maybe it's just a typo in your email but you put a $ infront of round() try 
removing that and see if it helps. If not are there any error messages that are 
showing up?
> 

--- End Message ---
--- Begin Message ---
Hi Jason,

I've tried lots of different things, including:

 echo "<br>" . round(68500, 1000) . " ROUNDED";

thinking that might be it, but i'm stumped

This is the example I was given (And have to go by):

"If the loan amount is $68500.00, the insurace will be based on
$69000.00 as the amount is always rounded up to the next $1000."

Maybe i'm just looking at it wrong but i'm stumped.

Chris


On Sun, Jan 15, 2012 at 8:41 PM, Jason Pruim <li...@pruimphotography.com> wrote:
>
>
> Sent from my iPhone
>
> On Jan 15, 2012, at 8:25 PM, "Christopher J Payne" <oxygene...@gmail.com> 
> wrote:
>
>> Hi everyone,
>>
>>
>>
>> I am having a hard time with a numerical problem.
>>
>>
>>
>> I need to round some numbers up and I've tried $round($number) and it
>> doesn't work so I'm misunderstanding something.
>>
>>
>>
>> For example, if a user inputs 685000 I need it to round up to 690000 or if
>> they input 149560 I need it to round up to 150000.  What is the correct way
>> to do this as everything I have tried doesn't seem to affect the user
>> inputted figure at all.
>>
>>
>>
>> Anyway help would REALLY be appreciated, I'm sure it's really simple but for
>> the life of me I'm stumped on why it's not working.
>>
>
> Maybe it's just a typo in your email but you put a $ infront of round() try 
> removing that and see if it helps. If not are there any error messages that 
> are showing up?
>>

--- End Message ---
--- Begin Message ---
On 16/01/2012, at 2:48 PM, Chris Payne wrote:

> Hi Jason,
> 
> I've tried lots of different things, including:
> 
> echo "<br>" . round(68500, 1000) . " ROUNDED";
> 
> thinking that might be it, but i'm stumped
> 
> This is the example I was given (And have to go by):
> 
> "If the loan amount is $68500.00, the insurace will be based on
> $69000.00 as the amount is always rounded up to the next $1000."
> 
> Maybe i'm just looking at it wrong but i'm stumped.
> 
> Chris


The round() function only rounds decimal values. You can use this to emulate 
rounding to a near power of ten by dividing, rounding, then multiplying again. 
i.e. echo "<br>" . round(68500/1000) * 1000 . " ROUNDED";
---
Simon Welsh
Admin of http://simon.geek.nz/


--- End Message ---
--- Begin Message ---
On 1/15/2012 8:48 PM, Chris Payne wrote:
Hi Jason,

I've tried lots of different things, including:

  echo "<br>" . round(68500, 1000) . " ROUNDED";

thinking that might be it, but i'm stumped

This is the example I was given (And have to go by):

"If the loan amount is $68500.00, the insurace will be based on
$69000.00 as the amount is always rounded up to the next $1000."

Maybe i'm just looking at it wrong but i'm stumped.

Chris


On Sun, Jan 15, 2012 at 8:41 PM, Jason Pruim<li...@pruimphotography.com>  wrote:

Sent from my iPhone

On Jan 15, 2012, at 8:25 PM, "Christopher J Payne"<oxygene...@gmail.com>  wrote:

Hi everyone,



I am having a hard time with a numerical problem.



I need to round some numbers up and I've tried $round($number) and it
doesn't work so I'm misunderstanding something.



For example, if a user inputs 685000 I need it to round up to 690000 or if
they input 149560 I need it to round up to 150000.  What is the correct way
to do this as everything I have tried doesn't seem to affect the user
inputted figure at all.



Anyway help would REALLY be appreciated, I'm sure it's really simple but for
the life of me I'm stumped on why it's not working.

Maybe it's just a typo in your email but you put a $ infront of round() try 
removing that and see if it helps. If not are there any error messages that are 
showing up?
http://php.net/manual/en/function.round.php

From the page:

|<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?> |



--- End Message ---
--- Begin Message ---
On Jan 15, 2012, at 19:00, "Simon J Welsh" 
<si...@welsh.co.nz<mailto:si...@welsh.co.nz>> wrote:

On 16/01/2012, at 2:48 PM, Chris Payne wrote:

"If the loan amount is $68500.00, the insurace will be based on
$69000.00 as the amount is always rounded up to the next $1000."

The round() function only rounds decimal values. You can use this to emulate 
rounding to a near power of ten by dividing, rounding, then multiplying again. 
i.e. echo "<br>" . round(68500/1000) * 1000 . " ROUNDED";

You can also pass a second parameter to round() that indicates the precision to 
round to. If you pass a negative precision value, you can round to higher-order 
digits. For example, pass -3 to round to the nearest thousand.

Having said that, based on the quote above, I believe this would be an 
incorrect solution to the problem. It sounds like the value is simply always 
rounded up to the nearest thousand, which means round() is not the function to 
use as it will sometimes round down. Instead ceil() should be used, as it 
always rounds up to the next whole number/integer. It lacks a precision 
argument, however, so the OP would need to use the divide-adjust-multiple trick 
you provided to make it work. That is, something like this:

$newValue = ceil(68500 / 1000) * 1000

Numbers smaller than 1000 will need to be handled as an edge case, since this 
algorithm will "adjust" them to zero for you (same as when using round(), 
incidentally). If negative numbers are valid inputs, they'll also need careful 
review to ensure correct behavior.

Hope that helps.

--
Bob Williams

________________________________
Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

--- End Message ---
--- Begin Message ---

On 1/15/2012 9:24 PM, Robert Williams wrote:
On Jan 15, 2012, at 19:00, "Simon J 
Welsh"<si...@welsh.co.nz<mailto:si...@welsh.co.nz>>  wrote:

On 16/01/2012, at 2:48 PM, Chris Payne wrote:

"If the loan amount is $68500.00, the insurace will be based on
$69000.00 as the amount is always rounded up to the next $1000."

The round() function only rounds decimal values. You can use this to emulate rounding to a near power of 
ten by dividing, rounding, then multiplying again. i.e. echo "<br>" . round(68500/1000) * 
1000 . " ROUNDED";

round() rounds floating point which I suppose includes decimals, but decimal tends to have a fixed number of decimal places.


float *round* ( float $val [, int $precision= 0 [, int $mode= PHP_ROUND_HALF_UP ]] )



--- End Message ---
--- Begin Message ---
Hi there,

A big thank you to all of you who took time to help me with my numeric
problem from earlier, it's been a huge help :-)

Chris

--- End Message ---
--- Begin Message ---
Hi, in ASP, sessions expire when the client does not request an asp
page for more than 20 min. (The 20 min thing is a server level setting
- which can be changed by IIS settings )  And sessions work out of the
box.

I use sessions a lot. So, most likely, I would keep that style in my
PHP apps too.

I read the following about PHP sessions...  I wanted to know how
accurate this info is.

<quote>
The default behaviour for sessions is to keep a session open
indefinitely and only to expire a session when the browser is closed.
This behaviour can be changed in the php.ini file by altering the
line:

session.cookie_lifetime = 0
If you wanted the session to finish in 5 minutes you would set this to:

Listing 23 Keeping a session alive for five minutes (listing-23.txt)
session.cookie_lifetime = 300.
Remember to restart your web server after making this change.
</quote>


Now, if this info is correct and it is this simple, why do we have
some elaborate posts like this one?

http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes


What do you do when you write a PHP app that relies on sessions? how
do you manage the server memory allocation issues?
Say you wanted to keep session vars alive for 20 min ( from the last
request from the client ) and you wanted your server to completely
empty the session if there no request, no new php page is requested
from that client within that next 20 min. And if a client requests a
page say on the 19th min, session gets extended another 20 from that
time on, just like the ASP works.

My second question on session is abut keeping sessions apart from one
another - if such a concept exists...

Let's say you have a session var FirstName in app1 and another session
variable exactly named as FirstName in app2.
how do you keep them seperate?

In ASP, I create a virtual app at the IIS server - assigning a virtual
dir path to the app, and from that point on, any page being served
under that virtual path is treated as an isolated ASP app and thus the
sessions are kept isolated and not get mixed up by asp pages that do
not live under that virtual app path.

Is this concept even applicable in PHP?

Thanks

--- End Message ---

Reply via email to