Re: [PHP] Numeric help needed

2012-01-15 Thread Curtis Maurand


On 1/15/2012 9:24 PM, Robert Williams wrote:

On Jan 15, 2012, at 19:00, "Simon J 
Welsh"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 "" . 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 ]] )





Re: [PHP] Numeric help needed

2012-01-15 Thread Robert Williams
On Jan 15, 2012, at 19:00, "Simon J Welsh" 
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 "" . 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).


Re: [PHP] Numeric help needed

2012-01-15 Thread Curtis Maurand

On 1/15/2012 8:48 PM, Chris Payne wrote:

Hi Jason,

I've tried lots of different things, including:

  echo "" . 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  wrote:


Sent from my iPhone

On Jan 15, 2012, at 8:25 PM, "Christopher J Payne"  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 69 or if
they input 149560 I need it to round up to 15.  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:

| |




Re: [PHP] Numeric help needed

2012-01-15 Thread Simon J Welsh
On 16/01/2012, at 2:48 PM, Chris Payne wrote:

> Hi Jason,
> 
> I've tried lots of different things, including:
> 
> echo "" . 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 "" . round(68500/1000) * 1000 . " ROUNDED";
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Numeric help needed

2012-01-15 Thread Chris Payne
Hi Jason,

I've tried lots of different things, including:

 echo "" . 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  wrote:
>
>
> Sent from my iPhone
>
> On Jan 15, 2012, at 8:25 PM, "Christopher J Payne"  
> 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 69 or if
>> they input 149560 I need it to round up to 15.  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?
>>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Numeric help needed

2012-01-15 Thread Jason Pruim


Sent from my iPhone

On Jan 15, 2012, at 8:25 PM, "Christopher J Payne"  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 69 or if
> they input 149560 I need it to round up to 15.  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?
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Numeric help needed

2012-01-15 Thread Christopher J Payne
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 69 or if
they input 149560 I need it to round up to 15.  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.

 

Chris