On 9/27/2012 10:05 PM, Chris Payne 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
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
On Sep 17, 2011, at 3:46 AM, Cyril Lopez wrote:
From: Cyril Lopez cy...@nethik.fr
Date: September 16, 2011 10:58:28 AM EDT
To: php-general@lists.php.net
Subject: Round with money_format
Hi,
Can someone help me understand how money_format() rounds numbers ?
?php
setlocale(LC_ALL,
On Sep 17, 2011, at 10:56 AM, Bill Guion wrote:
On Sep 17, 2011, at 3:46 AM, Cyril Lopez wrote:
Can someone help me understand how money_format() rounds numbers ?
As someone else pointed out, rounding rules vary by locale, but I was taught
40+ years ago in graduate school programming
On 17 September 2011 15:56, Bill Guion bgu...@comcast.net wrote:
On Sep 17, 2011, at 3:46 AM, Cyril Lopez wrote:
From: Cyril Lopez cy...@nethik.fr
Date: September 16, 2011 10:58:28 AM EDT
To: php-general@lists.php.net
Subject: Round with money_format
Hi,
Can someone help me understand
On 16 September 2011 15:58, Cyril Lopez cy...@nethik.fr wrote:
Hi,
Can someone help me understand how money_format() rounds numbers ?
?php
setlocale(LC_ALL, 'fr_FR.UTF-8');
$price = 12.665;
echo money_format('%i',$price);
// 12.66 EUR, 12.67 EUR expected
$price2 = 12.666;
echo
On 16 Sep 2011, at 15:58, Cyril Lopez wrote:
Can someone help me understand how money_format() rounds numbers ?
?php
setlocale(LC_ALL, 'fr_FR.UTF-8');
$price = 12.665;
echo money_format('%i',$price);
// 12.66 EUR, 12.67 EUR expected
$price2 = 12.666;
echo
Oops...
On 16 Sep 2011, at 16:36, Stuart Dallas wrote:
On 16 Sep 2011, at 15:58, Cyril Lopez wrote:
Can someone help me understand how money_format() rounds numbers ?
?php
setlocale(LC_ALL, 'fr_FR.UTF-8');
$price = 12.665;
echo money_format('%i',$price);
// 12.66 EUR, 12.67 EUR
On Wed, 2008-12-24 at 20:38 +0100, Anders Norrbring wrote:
Rounding an integer to the closest divisor by ten is easy with round() and a
negative precision, but I turn out to be lost if I want to round to a given
number..
Example, round to the closest 5000, or closest 400? Any great ideas?
tedd 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
At 10:22 AM -0400 10/11/07, Nathan Nobbe wrote:
On 10/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:
At 4:18 PM -0600 10/10/07,
mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:
I disagree. I will need to see an example where the round() is inaccurate.
You may disagree if you
Yes, but precision is not the issue.
It doesn't make any difference if you are rounding.
You still have to make a decision
Uuhm, what was $t on the platform before the round please (the +=
.000..1 post)? Then that will confirm that precision is not the
problem.
Also,
Yes, but precision is not the issue.
php -r '$t=123.45; echo $t . \n; $t+=0.001; echo $t . \n;'
123.45
123.451
php -r '$t=123.45; echo $t . \n; $t+=0.0001; echo $t . \n;'
123.45
123.45
php -r '$t=123.45678901234567; echo $t . \n;'
123.45678901235
Geee garbage in,
At 11:08 AM -0700 10/12/07, =?UTF-8?Q?J=C3=BCrgen_Wind?= wrote:
It's a question of what you expect from a rounding function.
If you work with reals on a computer you always have a bit of fuzzynes
due to the internal conversions from float to binary and resulting
truncations.
It is only reals
At 12:55 PM -0700 10/12/07, Instruct ICC wrote:
Yes, but precision is not the issue.
php -r '$t=123.45; echo $t . \n; $t+=0.001; echo $t . \n;'
123.45
123.451
php -r '$t=123.45; echo $t . \n; $t+=0.0001; echo $t . \n;'
123.45
123.45
php -r
On 10/11/07, tedd [EMAIL PROTECTED] wrote:
At 4:18 PM -0600 10/10/07, [EMAIL PROTECTED] wrote:
I disagree. I will need to see an example where the round() is
inaccurate.
You may disagree if you wish, but the php function round() is
inaccurate by definition -- all *rounding* algorithms are
At 4:18 PM -0600 10/10/07, [EMAIL PROTECTED] wrote:
I disagree. I will need to see an example where the round() is inaccurate.
You may disagree if you wish, but the php function round() is
inaccurate by definition -- all *rounding* algorithms are inaccurate.
My claim is the there are more
On 10/10/07, tedd [EMAIL PROTECTED] wrote:
Hi gang:
While we're entertaining algorithms, has anyone else noticed that
php's round() isn't the most accurate algorithm to round?
Cheers,
tedd
--
---
http://sperling.com http://ancientstones.com http://earthstones.com
Yes. sprintf
On 10/10/07, tedd [EMAIL PROTECTED] wrote:
Hi gang:
While we're entertaining algorithms, has anyone else noticed that
php's round() isn't the most accurate algorithm to round?
there is a function that uses the bc math library on the bc math
pagehttp://www.php.net/manual/en/ref.bc.php
;
While we're entertaining algorithms, has anyone else noticed that
php's round() isn't the most accurate algorithm to round?
For those that replied that there is a problem, can you provide examples?
precision
The optional number of decimal digits to round to, defaults to 0
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.
Why arent you just using sprintf?
$var = 5.555;
printf(%.2f, $var); # output : 5.56
printf(%.1f, $var); # output : 5.6
printf(%.0f, $var); # output : 6
On 10/10/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
While we're entertaining algorithms, has anyone else noticed that
php's round()
Koen van den Boogaart wrote:
Is it expected behaviour that
?php var_dump( round(-0.26) ); ?
outputs
float(-0)
Yes. You (probably) want:
?php
var_dump(round(-0.26, 1));
?
http://uk.php.net/manual/en/function.round.php
--
Richard Heyes
+44 (0)844 801 1072
No, I want it to go to float(0), so minus the minus. -0 doesn't exist in
math, as far as I know. Probably a precision thing.
Richard Heyes [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Koen van den Boogaart wrote:
Is it expected behaviour that
?php var_dump( round(-0.26) ); ?
Koen van den Boogaart wrote:
Is it expected behaviour that
?php var_dump( round(-0.26) ); ?
outputs
float(-0)
What version of PHP are you running.
I'm running 5.1.6 and I get float(0)
--
Jim Lucas
Some men are born to greatness, some achieve greatness,
and some have greatness
Koen van den Boogaart wrote:
No, I want it to go to float(0), so minus the minus. -0 doesn't exist in
math, as far as I know. Probably a precision thing.
Ok, then try abs() first then.
--
Richard Heyes
+44 (0)844 801 1072
http://www.websupportsolutions.co.uk
Knowledge Base and HelpDesk
On 8/29/07, Richard Heyes [EMAIL PROTECTED] wrote:
Koen van den Boogaart wrote:
No, I want it to go to float(0), so minus the minus. -0 doesn't exist in
math, as far as I know. Probably a precision thing.
Ok, then try abs() first then.
--
Richard Heyes
+44 (0)844 801 1072
Daniel Brown wrote:
On 8/29/07, Richard Heyes [EMAIL PROTECTED] wrote:
Koen van den Boogaart wrote:
No, I want it to go to float(0), so minus the minus. -0 doesn't exist in
math, as far as I know. Probably a precision thing.
Ok, then try abs() first then.
--
Richard Heyes
+44 (0)844 801 1072
What if I expected -1 for the last answer?
Then only use abs() if the result from round() is zero;
--
Richard Heyes
+44 (0)844 801 1072
http://www.websupportsolutions.co.uk
Knowledge Base and HelpDesk software
that can cut the cost of online support
--
PHP General Mailing List
2007. 08. 29, szerda keltezéssel 09.29-kor Jim Lucas ezt írta:
Daniel Brown wrote:
On 8/29/07, Richard Heyes [EMAIL PROTECTED] wrote:
Koen van den Boogaart wrote:
No, I want it to go to float(0), so minus the minus. -0 doesn't exist in
math, as far as I know. Probably a precision thing.
On 8/29/07, Zoltán Németh [EMAIL PROTECTED] wrote:
Think this through before you respond...
Try this
?php
var_dump( round(-0.26) );
var_dump( abs( round(-0.26) ) );
var_dump( round(-1.26) );
var_dump( abs( round(-1.26) ) );
?
does this give you the desired results?
What
Daniel Brown wrote:
On 8/29/07, Zoltán Németh [EMAIL PROTECTED] wrote:
Think this through before you respond...
Try this
?php
var_dump( round(-0.26) );
var_dump( abs( round(-0.26) ) );
var_dump( round(-1.26) );
var_dump( abs( round(-1.26) ) );
?
does this give you the desired results?
What
I'm running 5.2.3. Reaction on above discussion: of course this problem can
be solved with all sorts of solutions, but my question is: is it good that a
function returns a number that doesn't exist? I once posted a bug report
about a wrong round()-result, though it wasn't a bug, but a
. Unless someone has some trick that I don't know about, ABS will
NEVER return a negative number.
-Original Message-
From: Jim Lucas [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 29, 2007 1:43 PM
To: Daniel Brown
Cc: Zoltán Németh; php-general@lists.php.net
Subject: Re: [PHP] Round
Daniel
PHP-Gen wrote:
I believe there is some confusion on what ABS actually does. Ignoring all
the rounding that you are trying to do ABS is a very simple function.
ABS definition: Returns the absolute value of number.
What that means is.
Abs(1) = 1
Abs(2) = 2
Abs(3) = 3
Abs(0) = 0
Abs(-1) = 1
On Wed, August 29, 2007 11:38 am, Zoltán Németh wrote:
2007. 08. 29, szerda keltezéssel 09.29-kor Jim Lucas ezt Ãrta:
Daniel Brown wrote:
On 8/29/07, Richard Heyes [EMAIL PROTECTED] wrote:
Koen van den Boogaart wrote:
No, I want it to go to float(0), so minus the minus. -0
doesn't exist
Some information from Wikipedia: http://en.wikipedia.org/wiki/Negative_zero.
Says in math a negative zero doesn't exist, in computing it does. Strange
thing is that PHP4 and 5 until at least 5.1.6 (see Jim Lucas) round() gives
a float(0) and then 5.2.3 gives float(-0). I'll report a bug.
At 7:57 PM +0100 2/12/07, Marc Weber wrote:
On Mon, 12 Feb 2007 18:02:41 +0100, [EMAIL PROTECTED] wrote:
Is there an easy way in php to round to the nearest 500?
Yeah
$rouned = round($val/500) * 500;
I've always questioned the round() function.
I believe it has a downward bias, am I wrong?
For downward rounding, you'd always want to use floor() and use ceil() for
rounding up. round() rounds up on a 5, down on a 4 and below.
Example:
echo round(141.074, 2); // 141.07
echo round(141.065, 2); // 141.07
I thought round() (or maybe it was a rounding function in another language or
snip
Supposedly this is an accounting trick that
ultimatley works out in the end for proper rounding of money
values.
Yeah works out for who? Bet it doesn't for the guy paying :P
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
hah yeah, always worth a little skepticism, but it seemed to make some kind of
sense. If you always round up or always round down, that's obviously not
right and you end up losing potentially a lot of money or over-estimating the
money involved.
Founding up for 5 through 9 and down for 0
[EMAIL PROTECTED] wrote:
hah yeah, always worth a little skepticism, but it seemed to make some kind of
sense. If you always round up or always round down, that's obviously not
right and you end up losing potentially a lot of money or over-estimating the
money involved.
Founding up for 5
Ok, screw work.. it's snowing out anyway (not that that makes a real difference
to doing PHP work inside), curiosity got the better of me.
btw.. the banker rounding code here was pulled from the round() manual page.
It's not what I read before, but it's the same concept:
function
Ahh.. good call.
http://en.wikipedia.org/wiki/Rounding
Apprently it's called banker's rounding or statistician's rounding and is a
little more complicated than just looking at the odd/even of the digit being
arounded.
This is starting to get into some heavy math theory and scary stuff that
- Original Message -
From: Jon Anderson [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
hah yeah, always worth a little skepticism, but it seemed to make some
kind of sense. If you always round up or always round down, that's
obviously not right and you end up losing potentially a lot
I don't buy zero doesn't count. But again, this is getting into serious
math. It should be good enough to say 0-4 = 0, 5-9 = 10, but if you don't keep
strict high precision throughout the whole process and round at every step,
things are going to be off no matter what. It's just a matter of
blackwater dev wrote:
Is there an easy way in php to round to the nearest 500?
So if I have 600, I 500 and if I have 800 I want 1000?
Multiply by 2, round to 1000, divide by 2. Maybe there's an easier way,
but that's what I use.
600*2 = 1200, round(1200,-3) = 1000, 1000/2 = 500
800*2 =
On Mon, 2007-02-12 at 11:52 -0500, blackwater dev wrote:
Is there an easy way in php to round to the nearest 500?
So if I have 600, I 500 and if I have 800 I want 1000?
This should work:
?php
$rounded = round( $someValue / 500 ) * 500;
?
Cheers,
Rob.
--
$num = 749;
$rounded = round($num * 2, -3) / 2;
echo $rounded;
-TG
= = = Original message = = =
Is there an easy way in php to round to the nearest 500?
So if I have 600, I 500 and if I have 800 I want 1000?
Thanks!
___
Sent by
On Mon, 2007-02-12 at 11:59 -0500, Jon Anderson wrote:
blackwater dev wrote:
Is there an easy way in php to round to the nearest 500?
So if I have 600, I 500 and if I have 800 I want 1000?
Multiply by 2, round to 1000, divide by 2. Maybe there's an easier way,
but that's what I use.
-Message d'origine-
De : Robert Cummings [mailto:[EMAIL PROTECTED]
Envoyé : lundi 12 février 2007 18:00
À : blackwater dev
Cc : php-general@lists.php.net
Objet : Re: [PHP] round to nearest 500?
On Mon, 2007-02-12 at 11:52 -0500, blackwater dev wrote:
Is there an easy way
On Mon, 12 Feb 2007 18:02:41 +0100, [EMAIL PROTECTED] wrote:
Is there an easy way in php to round to the nearest 500?
Yeah
$rouned = round($val/500) * 500;
Marc
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
At 3:17 PM -0500 5/19/06, Richard Lynch wrote:
On Fri, May 19, 2006 1:27 pm, Sébastien Guay wrote:
I searched the archives but did not found anything.
It seem that the round function behavior has changed in php 4.4.x (I
don't
have 4.4.1 handy for testing).
In 4.3.11, the output of
I seem to remember something about rounding functions and accounting.. that
there's a rule in accounting that says if the trailing number is even you round
down, odd you round up.. or something like that. I know that's different than
standard 'math' but in accounting it apparently helps deal
On Fri, May 19, 2006 1:27 pm, Sébastien Guay wrote:
I searched the archives but did not found anything.
It seem that the round function behavior has changed in php 4.4.x (I
don't
have 4.4.1 handy for testing).
In 4.3.11, the output of round(23.005,2) is 23.01 which is
mathematically
Thanx!
/G
- Original Message -
From: George Pitcher [EMAIL PROTECTED]
To: Gustav Wiberg [EMAIL PROTECTED]
Sent: Monday, September 12, 2005 10:55 AM
Subject: RE: [PHP] Round with ONE-decimal... always...
Look at sprint_f() in the manual.
George
-Original Message-
From
besides sprintf, number_format will also do it:
number_format(6, 1, ',', '');// Outputs '6,0'
Jordan
On Sep 12, 2005, at 3:52 AM, Gustav Wiberg wrote:
Hi there!
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)
Thank you for everyone's suggestions. Using them
(and a few other things I've found elsewhere), I've
come up with the following function:
function roundToNearest( $number, $toNearest = 5 ) {
$retval = 0;
$mod = $number % $toNearest;
if( $mod = 0 ) {
$retval = ( $mod ( $toNearest /
On 4/28/05, Chris Boget [EMAIL PROTECTED] wrote:
I realize this is a dumb question but I just can't come
up with an equation that will do this and I don't see an
internal PHP function (for version 4.3) that will do this...
Basically I need to come up with an equation/algorithm
that will round
I think the formula you are looking for is something like this:
round( y/x, 0) * x
With y being your number and x being the nearest increment number to
round to.
On Apr 28, 2005, at 4:10 PM, Chris Boget wrote:
I realize this is a dumb question but I just can't come
up with an equation that will
On 4/28/05, Greg Donald [EMAIL PROTECTED] wrote:
do {
$num++;
} while( $num % 500 );
Actually that fails for the base number 500. This works for everything:
#!/usr/bin/php
?php
$num = isset( $_SERVER[ 'argv' ][ 1 ] )
? $_SERVER[ 'argv' ][ 1 ]
: 0;
if( $num % 500 )
{
do {
I realize this is a dumb question but I just can't come up
with an equation that will do this and I don't see an
internal PHP function (for version 4.3) that will do this...
Basically I need to come up with an equation/algorithm that
will round any number up/down to the nearest X.
I
On 16 Apr 2005 Chris Knipe wrote:
I'm not sure if round() is what I am after. I want to round whole numbers
to the closest 10 - thus, not decimals, etc.
Just use a precision of -1. For example round(125, -1) will return
130.
--
Tom
--
PHP General Mailing List (http://www.php.net/)
To
You can use the number_format($number, decimal_places) function.
-Original Message-
From: blackwater dev [mailto:[EMAIL PROTECTED]
Sent: 26 January 2005 01:33 PM
To: php-general@lists.php.net
Subject: [PHP] round
Hello,
I have these values:
8.26456
9.7654
3.
5.2689
and I want
On Wed, 26 Jan 2005 06:32:32 -0500
blackwater dev [EMAIL PROTECTED] 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
You can try the sprintf()
On Tue, Dec 16, 2003 at 11:13:25AM +, Scott McDaid wrote:
:
: Hi there. I've been looking at the behaviour of the round functionality in
: PHP. We're currently still using v4.2.3, (but the documentation seems to
: suggest it's the same for versions after this).
:
: Doing the following
On 16 December 2003 11:13, Scott McDaid wrote:
Hi there. I've been looking at the behaviour of the round
functionality in PHP. We're currently still using v4.2.3, (but the
documentation seems to
suggest it's the same for versions after this).
Doing the following rounds always rounds *up*
echo (iny)$number;
Shaun wrote:
Hi,
I have a query that returns a number from culculation in my table. It
returns say 4.00, 8.75, 0.00, 12.50 etc. How format the number so that the
trailing zeros aer removed i.e. 4, 8.75, 0, 12.5 etc?
Thanks for your help
--
PHP General Mailing List
Hi!
ceil -- Round fractions up
round -- Rounds a float
floor -- Round fractions down
Joe
- Original Message -
From: Ralph [EMAIL PROTECTED]
To: PHP General Mailing List [EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 2:51 PM
Subject: [PHP] Round Off $ prices
How do I round off
Ok, after some more fiddling, I'm really close to getting this to work.
The script seems to correctly generate a schedule if an odd number of teams
are specified:
Given an array of 5 teams, A through E, the following pairs are generated:
Round 1 - A/E, B/D
Round 2 - D/E, A/C
Round 3 - C/D, B/E
, $last_team);
if ($even) {
array_push($teamarray, $last_team_save);
}
Hope this helps anyone else who needs it.
Chad
-Original Message-
From: Chad Day [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 30, 2002 2:03 PM
To: php general
Subject: RE: [PHP] Round robin
Correction, MySQL is not returning floor, since it returns 2 for round(1.5). - I
didn't see it.
MySQL should not return 2 for round(2.5), but it should return 3. I think it's
MySQL bug.
How about ask in MySQL mailing list?
--
Yasuo Ohgaki
""Yasuo Ohgaki"" [EMAIL PROTECTED] wrote in message
In article 9b6c4v$m41$[EMAIL PROTECTED] you write:
Correction, MySQL is not returning floor, since it returns 2 for round(1.5). - I
didn't see it.
MySQL should not return 2 for round(2.5), but it should return 3. I think it's
MySQL bug.
How about ask in MySQL mailing list?
I don't think it's
MySQL is returning floor. (I'm not a MySQL heavy user, though :)
PHP's result is correct for its function name, I think.
If MySQL returns floor for round(), how about use floor() in PHP?
Regards,
--
Yasuo Ohgaki
"Lee Howard" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL
74 matches
Mail list logo