php-general Digest 28 Sep 2012 13:27:30 -0000 Issue 7984

Topics (messages 319289 through 319294):

Round help needed
        319289 by: Chris Payne
        319290 by: Daniel Brown

Re: Static constructor support
        319291 by: shiplu

Here's my rounding
        319292 by: Chris Payne
        319293 by: Simon J Welsh
        319294 by: Jim Giner

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 ---
Hi everyone,

I'm having one of those nights where nothing is working, please help

What I have is this:

$rounded_number = round($test, -3);

Here's the problem i'm having, I need it to increment to the nearest 1000
but it seems to only work if the number is over 500.  For example:


123666  WILL round to 124000 BUT if I put 123085 (As an example) it doesn't
round it, it just stays at 123085 - I know it's probably something totally
ridiculously simple but i'm having a mental block tonight.

Any help would really be appreciated.

Chris
http://www.youtube.com/user/zoolook3264

--- End Message ---
--- Begin Message ---
On Thu, Sep 27, 2012 at 11:05 PM, Chris Payne <oxygene...@gmail.com> wrote:
> Hi everyone,
>
> I'm having one of those nights where nothing is working, please help
>
> What I have is this:
>
> $rounded_number = round($test, -3);
>
> Here's the problem i'm having, I need it to increment to the nearest 1000
> but it seems to only work if the number is over 500.  For example:
>
>
> 123666  WILL round to 124000 BUT if I put 123085 (As an example) it doesn't
> round it, it just stays at 123085 - I know it's probably something totally
> ridiculously simple but i'm having a mental block tonight.
>
> Any help would really be appreciated.

     Sounds like one of those "should be obvious, but isn't" issues.
This gives the desired result:

        <?php echo round(123085,-3); ?>

    So I wonder if it's your variable (perhaps even type-casting) or
some other portion of your code.  Can you elaborate and share some of
your bytes with the class, Mr. Payne?

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
Somewhere in Internet I found this form.

class  MyClass{
    static private $somevar;
    static public function init(){
    }
} MyClass::init();

Now I am using this consistently.

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader

--- End Message ---
--- Begin Message ---
$test2 = '253177';
echo $tes2 . " rounded to: ";
$rounded_number = round($test2,-3);
echo $rounded_number;

Is it SUPPOSED to happy a number is sent to this little system and it's
SUPPOSED to round the number up.  So if the number was 144035 the system
should look at it and say "Hey uo,
we need to round this up"  So basicially I need it to convert in
thousands.  Even if the total is a fraction over it still needs to ne
calculated as the next thousand up.

Sprru of o'm confusing you, i'm very tired.  So basically, just make the
last 4 numbers always round up.  255000 would be correct - 255590 would
beINSORERECT as it should display 255600.

Hope that helped someone to help me :-)

xxx
Chris

--- End Message ---
--- Begin Message ---
On 28/09/2012, at 6:08 PM, Chris Payne <oxygene...@gmail.com> wrote:

> $test2 = '253177';
> echo $tes2 . " rounded to: ";
> $rounded_number = round($test2,-3);
> echo $rounded_number;
> 
> Is it SUPPOSED to happy a number is sent to this little system and it's
> SUPPOSED to round the number up.  So if the number was 144035 the system
> should look at it and say "Hey uo,
> we need to round this up"  So basicially I need it to convert in
> thousands.  Even if the total is a fraction over it still needs to ne
> calculated as the next thousand up.
> 
> Sprru of o'm confusing you, i'm very tired.  So basically, just make the
> last 4 numbers always round up.  255000 would be correct - 255590 would
> beINSORERECT as it should display 255600.
> 
> Hope that helped someone to help me :-)
> 
> xxx
> Chris


I would use something similar to $rounded_number = ceil($test2/1000)*1000;
---
Simon Welsh
Admin of http://simon.geek.nz/


--- End Message ---
--- Begin Message ---
On 9/28/2012 2:11 AM, Simon J Welsh wrote:
On 28/09/2012, at 6:08 PM, Chris Payne <oxygene...@gmail.com> wrote:

$test2 = '253177';
echo $tes2 . " rounded to: ";
$rounded_number = round($test2,-3);
echo $rounded_number;

Is it SUPPOSED to happy a number is sent to this little system and it's
SUPPOSED to round the number up.  So if the number was 144035 the system
should look at it and say "Hey uo,
we need to round this up"  So basicially I need it to convert in
thousands.  Even if the total is a fraction over it still needs to ne
calculated as the next thousand up.

Sprru of o'm confusing you, i'm very tired.  So basically, just make the
last 4 numbers always round up.  255000 would be correct - 255590 would
beINSORERECT as it should display 255600.

Hope that helped someone to help me :-)

xxx
Chris


I would use something similar to $rounded_number = ceil($test2/1000)*1000;
---
Simon Welsh
Admin of http://simon.geek.nz/

From my days as a math major, rounding doesn't always go up - it goes to the nearest level that you have indicated. As Simon shows you, you want to ceil to always go up, and floor to always go down. Neat function names actually... :)
--- End Message ---

Reply via email to