RE: [PHP] RE: round()

2007-10-12 Thread tedd

At 7:30 PM -0700 10/11/07, Instruct ICC wrote:



Now I see why BCMath was mentioned.


Yes, but precision is not the issue.

It doesn't make any difference if you are rounding.

(a) 1.489123451985765

or

(b) 148912345198576.5

You still have to make a decision as to if the above (a) rounds to:

(a) 1.48912345198577

or

(a) 1.48912345198576

or the above (b) rounds to:

(b)148912345198577

or

(b) 148912345198576

It's a question of rounding, not precision.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] RE: round()

2007-10-12 Thread Nathan Nobbe
On 10/12/07, tedd [EMAIL PROTECTED] wrote:

 At 7:30 PM -0700 10/11/07, Instruct ICC wrote:
 
 
 Now I see why BCMath was mentioned.

 Yes, but precision is not the issue.

 It doesn't make any difference if you are rounding.

 (a) 1.489123451985765

 or

 (b) 148912345198576.5

 You still have to make a decision as to if the above (a) rounds to:

 (a) 1.48912345198577

 or

 (a) 1.48912345198576

 or the above (b) rounds to:

 (b)148912345198577

 or

 (b) 148912345198576

 It's a question of rounding, not precision.



precision is still an issue; after a certain number of digits are used as
the argument; round becomes inaccurate.
from the cases you listed above (a) 1.489123451985765
bcmath results in one of the possible results you listed, (a)
1.48912345198577;
round results in neither possible result.
 case (b) 148912345198576.5
bcmath results in one of the possible results, (b)148912345198577;
round results in neither possible result.

this is because the internal binary data type is already filled to capacity
when these calculations are imposed on that
data.  im not sure how bcmath handles this internally, but it appears to be
more precise and more accurate.  results
will vary based on your hardware, but you can use the second tool i passed
out to find the breaking point on your
system and the first one to test possibilities against the breaking point.

[EMAIL PROTECTED] ~/working/www $ ./bcRound.php 1.489123451985765 14
round result: 1.48912345199
roundbc result: 1.48912345198577
Numerical Comparison: the results are the same
String Comparison: the results are different
[EMAIL PROTECTED] ~/working/www $ ./bcRound.php 148912345198576.5 0
round result: 148912345199000
roundbc result: 148912345198577.
Numerical Comparison: the results are the same
String Comparison: the results are different

i cant seem to get bcmath to choose the alternate rounding path in either
one of the cases.

-nathan


[PHP] RE: round()

2007-10-12 Thread tedd

At 11:26 AM -0700 10/11/07, =?UTF-8?Q?J=C3=BCrgen_Wind?= wrote:

I get correct results:

5.2.4 PHP_VERSION
round(5.555,2):5.56
toFixed(5.555,2):5.56


You get correct results because the demand you made of the function was simple.

If you expand your demand to thousands of cases, then the bias will emerge.

Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] RE: round()

2007-10-11 Thread Jürgen Wind

I get correct results:

5.2.4 PHP_VERSION
round(5.555,2):5.56
toFixed(5.555,2):5.56


admin-214 wrote:
 
 While we're entertaining algorithms, has anyone else noticed that 
 
 php's round() isn't the most accurate algorithm to round?
 
  
 
 If you will refer to chafy's reply  on 28-Feb-2007 06:13
 http://us2.php.net/manual/en/function.round.php#73537 
 
 The function round numbers to a given precision.
 
 function toFixed($number, $round=2)
 { 
 
 $tempd = $number*pow(10,$round);
 $tempd1 = round($tempd);
 $number = $tempd1/pow(10,$round);
 return $number;
  
 }
 echo toFixed(5.555,2);  //return 5.56 
 
  
 
 If your rounding issue is passed 2 decimal places. I found this function
 covenant and problem solving. As for the accuracy  of the algorithm 
 
 I disagree. I will need to see an example where the round() is inaccurate.
 
  
 
 
 

-- 
View this message in context: 
http://www.nabble.com/round%28%29-tf4602528.html#a13161858
Sent from the PHP - General mailing list archive at Nabble.com.

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



[PHP] RE: round()

2007-10-11 Thread Jürgen Wind

well,
seems to be OS dependent:

PHP_OS:Linux (Suse 9.x 32bit) | PHP_VERSION:5.0.3
$t=1.255;
round($t,2):1.26
$t += .0001;
round($t,2):1.26


PHP_OS:WINNT (2000) | PHP_VERSION:5.2.4
$t=1.255;
round($t,2):1.25

$t += .0001;
round($t,2):1.26

-- 
View this message in context: 
http://www.nabble.com/round%28%29-tf4602528.html#a13164737
Sent from the PHP - General mailing list archive at Nabble.com.

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



RE: [PHP] RE: round()

2007-10-11 Thread Instruct ICC

 well,
 seems to be OS dependent:
 
 PHP_OS:Linux (Suse 9.x 32bit) | PHP_VERSION:5.0.3
 $t=1.255;
 round($t,2):1.26
 $t += .0001;
 round($t,2):1.26
 
 
 PHP_OS:WINNT (2000) | PHP_VERSION:5.2.4
 $t=1.255;
 round($t,2):1.25
 
 $t += .0001;
 round($t,2):1.26
 
 -- 
 View this message in context: 
 http://www.nabble.com/round%28%29-tf4602528.html#a13164737
 Sent from the PHP - General mailing list archive at Nabble.com.

First, you may have to be aware of floating point precision on your platform.
http://php.he.net/manual/en/language.types.float.php
The size of a float is platform-dependent

What is $t after $t += .0001; ?

Now I see why BCMath was mentioned.

_
Windows Live Hotmail and Microsoft Office Outlook – together at last.  Get it 
now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033

[PHP] Re: Round with ONE-decimal... always...

2005-09-12 Thread Mark Rees

 I want to adjust the round() -function a little...

 If I put round(6,0) there will be an output of 6
 If I put round(6,32) there will be an output of 6,3

 I want it to have 6,0 instead of just 6... I guess there is an easy
solution
 to this? Suggestions?

Have a look at this.

http://uk2.php.net/manual/en/function.number-format.php






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



Re: [PHP] Re: Round with ONE-decimal... always...

2005-09-12 Thread Gustav Wiberg


- Original Message - 
From: Mark Rees [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Monday, September 12, 2005 11:12 AM
Subject: [PHP] Re: Round with ONE-decimal... always...





I want to adjust the round() -function a little...

If I put round(6,0) there will be an output of 6
If I put round(6,32) there will be an output of 6,3

I want it to have 6,0 instead of just 6... I guess there is an easy

solution

to this? Suggestions?


Have a look at this.

http://uk2.php.net/manual/en/function.number-format.php






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



--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.21/96 - Release Date: 2005-09-10



Thanx!

/G
http://www.varupiraten.se/

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



[PHP] Re: round

2005-01-26 Thread M. Sokolewicz
use number_format()
Blackwater Dev wrote:
Hello,
I have these values:
8.26456
9.7654
3.
5.2689
and I want them rounded to two decimal places so I use the round :
round($value,2) which gives me, for example:
8.26
But, it also gives me 3 instead of 3.00.  How can I round but retain the 0's?
Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: ROUND inconsistency

2001-04-13 Thread Sinisa Milivojevic

Lee Howard writes:
 Using MySQL 3.23.32 on RedHat Linux 7.0...
 
 MySQL's ROUND function rounds 5 up when the preceding digit is odd and down
 when the preceding digit is even.
 
 mysql select round(1.5);
 ++
 | round(1.5) |
 ++
 |  2 |
 ++
 1 row in set (0.00 sec)
 
 mysql select round(2.5);
 ++
 | round(2.5) |
 ++
 |  2 |
 ++
 1 row in set (0.00 sec)
 
 I think that this is technically the correct behavior, scientifically,
 anyway.  However, this is not the common "lay-man's" method of rounding,
 which is to always round 5 up, as exhibited by PHP-4.0.4pl1...
 
   ? echo round(1.5); ?
   br
   ? echo round(2.5); ?
 
 Apache 1.3.14 output for this is:
 
   2
   3
 
 This discrepancy causes a difficulty in programming PHP and MySQL together,
 for example, because all of the rounding must be done in either PHP or
 MySQL but not both partially unless you want conflicting data.
 
 I would like to see MySQL ROUND() syntax expand to be ROUND(X,D,M) where
 optional M value indicates the method of rounding, the default being the
 current method.
 
 I would also like to see PHP round() syntax expand to be 
   double round (double val [, int precision] [, char method])
 where the optional method value indicates the method of rounding, the
 default being the current method.
 
 Thanks.
 
 Lee Howard


Hi!

This topic has been covered in all depth on [EMAIL PROTECTED]

Please search the archives on ROUND and you will find all info.


Regards,

Sinisa

    __ _   _  ___ ==  MySQL AB
 /*/\*\/\*\   /*/ \*\ /*/ \*\ |*| Sinisa Milivojevic
/*/ /*/ /*/   \*\_   |*|   |*||*| mailto:[EMAIL PROTECTED]
   /*/ /*/ /*/\*\/*/  \*\|*|   |*||*| Larnaca, Cyprus
  /*/ /*/  /*/\*\_/*/ \*\_/*/ |*|
  /*/^^^\*\^^^
 /*/ \*\Developers Team

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]