Re: [PHP] Rounding down?

2009-08-22 Thread Richard Heyes
Hi,

 Is there a way to round down to the nearest 50?

 Example: Any number between 400 and 449 I would 400 to be displayed; 450 to 
 499 would be 450; 500 to 549 would be 500, etc?

Off the top of my head: divide the number by 50, run floor() on the
result, then times it by 50.

1. 449 / 50 = 9.whatever
2. floor(9.whatever) = 9
3. 9 * 50 = 450

-- 
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
Lots of PHP and Javascript code - http://www.phpguru.org

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



Re: [PHP] Rounding down?

2009-08-22 Thread Ashley Sheridan
On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:
 Hi,
 
  Is there a way to round down to the nearest 50?
 
  Example: Any number between 400 and 449 I would 400 to be displayed; 450 to 
  499 would be 450; 500 to 549 would be 500, etc?
 
 Off the top of my head: divide the number by 50, run floor() on the
 result, then times it by 50.
 
 1. 449 / 50 = 9.whatever
 2. floor(9.whatever) = 9
 3. 9 * 50 = 450
 
 -- 
 Richard Heyes
 HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
 Lots of PHP and Javascript code - http://www.phpguru.org
 

It should be round() and not floor().

449 / 50 = 8.98
floor(8.98) = 8
8 * 50 = 400

round(8.98) = 9
9 * 50 = 450



Thanks,
Ash
http://www.ashleysheridan.co.uk




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



Re: [PHP] Rounding down?

2009-08-22 Thread Ron Piggott

Thanks; Amazing.  Ron

- Original Message - 
From: Ashley Sheridan a...@ashleysheridan.co.uk

To: Richard Heyes rich...@php.net
Cc: Ron Piggott ron@actsministries.org; php-general@lists.php.net
Sent: Saturday, August 22, 2009 9:02 AM
Subject: Re: [PHP] Rounding down?



On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:

Hi,

 Is there a way to round down to the nearest 50?

 Example: Any number between 400 and 449 I would 400 to be displayed; 
 450 to 499 would be 450; 500 to 549 would be 500, etc?


Off the top of my head: divide the number by 50, run floor() on the
result, then times it by 50.

1. 449 / 50 = 9.whatever
2. floor(9.whatever) = 9
3. 9 * 50 = 450

--
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
Lots of PHP and Javascript code - http://www.phpguru.org



It should be round() and not floor().

449 / 50 = 8.98
floor(8.98) = 8
8 * 50 = 400

round(8.98) = 9
9 * 50 = 450



Thanks,
Ash
http://www.ashleysheridan.co.uk










No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.409 / Virus Database: 270.13.64/2319 - Release Date: 08/22/09 
06:06:00



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



Re: [PHP] Rounding down?

2009-08-22 Thread דניאל דנון
I also wrote a function for that,

function round_to($number, $increments) {
$increments = 1 / $increments;
return (round($number * $increments) / $increments);
}

(Also published on php manual - round() )


On Sat, Aug 22, 2009 at 4:11 PM, Ron Piggott ron@actsministries.orgwrote:

 Thanks; Amazing.  Ron

 - Original Message - From: Ashley Sheridan 
 a...@ashleysheridan.co.uk
 To: Richard Heyes rich...@php.net
 Cc: Ron Piggott ron@actsministries.org; php-general@lists.php.net
 
 Sent: Saturday, August 22, 2009 9:02 AM
 Subject: Re: [PHP] Rounding down?


  On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:

 Hi,

  Is there a way to round down to the nearest 50?
 
  Example: Any number between 400 and 449 I would 400 to be displayed; 
 450 to 499 would be 450; 500 to 549 would be 500, etc?

 Off the top of my head: divide the number by 50, run floor() on the
 result, then times it by 50.

 1. 449 / 50 = 9.whatever
 2. floor(9.whatever) = 9
 3. 9 * 50 = 450

 --
 Richard Heyes
 HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
 Lots of PHP and Javascript code - http://www.phpguru.org


 It should be round() and not floor().

 449 / 50 = 8.98
 floor(8.98) = 8
 8 * 50 = 400

 round(8.98) = 9
 9 * 50 = 450



 Thanks,
 Ash
 http://www.ashleysheridan.co.uk






 



 No virus found in this incoming message.
 Checked by AVG - www.avg.com
 Version: 8.5.409 / Virus Database: 270.13.64/2319 - Release Date: 08/22/09
 06:06:00



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




-- 
Use ROT26 for best security


Re: [PHP] Rounding down?

2009-08-22 Thread Richard Heyes
Hi,

 It should be round() and not floor().

 449 / 50 = 8.98
 floor(8.98) = 8
 8 * 50 = 400

 round(8.98) = 9
 9 * 50 = 450

Not based on the examples given:

 Example: Any number between 400 and 449 I would 400 to be displayed

-- 
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
Lots of PHP and Javascript code - http://www.phpguru.org

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



Re: [PHP] Rounding down?

2009-08-22 Thread Richard Heyes
Hi,

 ...

A little modification:

?php
/**
* Rounds down to the nearest 50
*/
function myRound($val)
{
$units = intval(substr($val, -2));

return intval(substr($val, 0, -2) . ($units = 50 ? '50' : '00'));
}

echo myRound(449) . 'br /'; // 400
echo myRound(450) . 'br /'; // 450
echo myRound(356) . 'br /'; // 350
echo myRound(79) . 'br /';  // 50
?

PS I haven't checked if there's a PHP function for this.

-- 
Richard Heyes
HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
Lots of PHP and Javascript code - http://www.phpguru.org

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



Re: [PHP] Rounding down?

2009-08-22 Thread Clancy
On Sat, 22 Aug 2009 14:02:58 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:

On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:
 Hi,
 
  Is there a way to round down to the nearest 50?
 
  Example: Any number between 400 and 449 I would 400 to be displayed; 450 
  to 499 would be 450; 500 to 549 would be 500, etc?
 
 Off the top of my head: divide the number by 50, run floor() on the
 result, then times it by 50.
 
 1. 449 / 50 = 9.whatever
 2. floor(9.whatever) = 9
 3. 9 * 50 = 450
 
 -- 
 Richard Heyes
 HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
 Lots of PHP and Javascript code - http://www.phpguru.org
 

It should be round() and not floor().

449 / 50 = 8.98
floor(8.98) = 8
8 * 50 = 400

round(8.98) = 9
9 * 50 = 450

Definitely floor or int, not round.

Round 0.5-1.499 - 1
Floor 1.0-1.999 - 1

And if you really want to be accurate  you should allow for decimal conversion 
errors in
any operation involving floating point numbers.  Otherwise you cannot rely on 
(say) 50 not
being represented as 49.99, so that int or floor will give 49. In 
something like
this I usually add half of the precision I want to work to:

eg: $answer = 50* (int) (($x +0.5)/50);

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



Re: [PHP] rounding down

2004-11-26 Thread John Nichel
Brad Ciszewski wrote:
hi everyone, i am looking for a snipplet to round down a number. i was wondering if you could put a negative number in the round() statement to do this, i want it to round down even if its at something.9, as long as its not a whole number, if needs to be rounded down. can anyone help me?
http://us4.php.net/floor
--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] rounding down

2004-11-26 Thread David Bevan
On November 26, 2004 08:58, Brad Ciszewski wrote:
 hi everyone, i am looking for a snipplet to round down a number. i was
 wondering if you could put a negative number in the round() statement to do
 this, i want it to round down even if its at something.9, as long as its
 not a whole number, if needs to be rounded down. can anyone help me?

Searching on the php.net site in the manual is/can be your friend.

You want the floor() function.

Take a look at:
http://ca3.php.net/manual/en/function.floor.php

-- 
Regards,
David Bevan

We could learn a lot from crayons: 
some are sharp, some are pretty, some are dull, some have weird names, 
and all are different colorsbut they all exist very nicely in the same 
box. 

http://www.getanyideas.com

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



Re: [PHP] rounding down

2004-11-26 Thread Marek Kilimajer
Brad Ciszewski wrote:
hi everyone, i am looking for a snipplet to round down a number. i was wondering if you could put a negative number in the round() statement to do this, i want it to round down even if its at something.9, as long as its not a whole number, if needs to be rounded down. can anyone help me?
floor()
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] rounding average to one decimal point

2004-05-10 Thread Richard Davey
Hello Adam,

Monday, May 10, 2004, 7:03:36 PM, you wrote:

AW Hi, I have a randon group of numbers I need the average of.  When I add
AW them up and divide by how many there are and print the result, I get a
AW lot of decimal places.  The number comes out to look like 29.3529411765,
AW but I don't need that many decimal places.  rounding to one decimal place
AW will be fine.  anyway to trim off the excess decimal values? 

Try the round() function? :)

ceil() and floor() might help if you decide you don't want the extra
decimal places too.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: [PHP] rounding average to one decimal point

2004-05-10 Thread Daniel Clark
How about round()

echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000

http://www.phpbuilder.com/manual/function.round.php


 Hi, I have a randon group of numbers I need the average of.  When I add
 them up and divide by how many there are and print the result, I get a
 lot of decimal places.  The number comes out to look like 29.3529411765,
 but I don't need that many decimal places.  rounding to one decimal place
 will be fine.  anyway to trim off the excess decimal values?

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



Re: [PHP] rounding average to one decimal point

2004-05-10 Thread Adam Williams
On Mon, 10 May 2004, Richard Davey wrote:

 Hello Adam,
 
 Monday, May 10, 2004, 7:03:36 PM, you wrote:
 
 AW Hi, I have a randon group of numbers I need the average of.  When I add
 AW them up and divide by how many there are and print the result, I get a
 AW lot of decimal places.  The number comes out to look like 29.3529411765,
 AW but I don't need that many decimal places.  rounding to one decimal place
 AW will be fine.  anyway to trim off the excess decimal values? 
 
 Try the round() function? :)
 
 ceil() and floor() might help if you decide you don't want the extra
 decimal places too.
 
 


i didn't know about round(), guess i should check php.net/round next time 
;) thanks!

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



Re: [PHP] Rounding issue

2003-07-29 Thread Larry E . Ullman
$x = 4.5012412;
echo round($x, 2); // results in 4.5 ---  however I want 4.50!  I 
want 2
decimal places!
echo number_format ( round ($x, 2), 2);

Larry

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


Re: [PHP] Rounding issue

2003-07-29 Thread Curt Zirzow
* Thus wrote Kevin Ison ([EMAIL PROTECTED]):
 I need to know if there is a work around for the following scenerio...
 
 $x = 4.5012412;
 echo round($x, 2); // results in 4.5 ---  however I want 4.50!  I want 2
 decimal places!


 
 
 Is there a way to keep the zero from being dropped?  I have not been able to
 get the zero to stay there ... I realize this is the interpreters problem
 but I need the zero.

number_format(round($x, 2),2);

you can always control with printf functions, but number format is
designed specifically for that.


Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



Re: [PHP] Rounding issue

2003-07-29 Thread Kevin Ison
ahhh ok thanks guys!! That worked ... I knew it was something but I could
not remember which function...

thanks again!

Larry E . Ullman [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
  $x = 4.5012412;
  echo round($x, 2); // results in 4.5 ---  however I want 4.50!  I
  want 2
  decimal places!

 echo number_format ( round ($x, 2), 2);

 Larry




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



Re: [PHP] Rounding issue

2003-07-29 Thread Kevin Ison
ahhh ok thanks guys!! That worked ... I knew it was something but I could
not remember which function...

thanks again!

Curt Zirzow [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 * Thus wrote Kevin Ison ([EMAIL PROTECTED]):
  I need to know if there is a work around for the following scenerio...
 
  $x = 4.5012412;
  echo round($x, 2); // results in 4.5 ---  however I want 4.50!  I
want 2
  decimal places!


 
 
  Is there a way to keep the zero from being dropped?  I have not been
able to
  get the zero to stay there ... I realize this is the interpreters
problem
  but I need the zero.

 number_format(round($x, 2),2);

 you can always control with printf functions, but number format is
 designed specifically for that.


 Curt
 --
 I used to think I was indecisive, but now I'm not so sure.



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



[PHP] Re: PHP Rounding Time

2003-04-04 Thread Philip Hallstrom
I haven't quite thought this through, but I think something like this:

$remainder = $ts % 60;

if( $remainder  15 ) {
$ts = $ts - $remainder;
}else if( $remainder  15  $remainder  30 ) {
$ts = $ts + (30 - $remainder);
}else if( $remainder  30  $remainder  45 ) {
$ts = $ts - ($remainder - 30);
}else if( $remainder = 45 ) {
$ts = $ts + (60 - $remainder);
}

something close to that I think...

On Fri, 4 Apr 2003, Jay Fitzgerald wrote:

 I apologize in advance for my constant nub questions..

 How can I round the current time up or down to the nearest 1/2 hour?

 eg:
 timeranges:

 0900 through 0915 == 0900
 0916 through 0930 == 0930
 0931 through 0945 == 0930
 0946 through 1000 == 1000


 Jay Fitzgerald, Design Director
 Bayou Internet - http://www.bayou.com
 Toll Free: 888.30.BAYOU (22968)
 Vox: 318.338.2034 / Fax: 318.338.2506
 E-Mail: [EMAIL PROTECTED]
 ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf



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


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



Re: [PHP] Rounding

2003-02-20 Thread Ernest E Vogelsinger
At 22:17 20.02.2003, Van Andel, Robbert spoke out and said:
[snip]
How do I round a number to the nearest 10 or even 5.  Say I have a
number like 12.  Is there an easy way to round that up to 15 or 20?
[snip] 

function round_to($number, $full, $isup=true)
{
$factor = $number % $full;
if ($isup) {
if ($factor) $factor = $full - $factor;
$result = $number + ($factor ? $factor : 0);
}
else
$result = $number - $factor;
return $result;
}

$x = 12;
$to = 5;
echo $x = , round_to($x, $to), \n, $x = , round_to($x, $to, false);


-- 
   O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
^ http://www.vogelsinger.at/


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




Re: [PHP] Rounding

2003-02-20 Thread Jason Wong
On Friday 21 February 2003 05:17, Van Andel, Robbert wrote:
 How do I round a number to the nearest 10 or even 5.  Say I have a
 number like 12.  Is there an easy way to round that up to 15 or 20?

To round to the nearest 5:

  Divide by 5
  Round to the nearest integer
  Multiply by 5

I'll leave you to work out how to round to nearest 10.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Man belongs wherever he wants to go.
-- Wernher von Braun
*/


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




Re: [PHP] Rounding

2003-02-20 Thread Steve Keller
At 2/21/2003 05:29 AM, Jason Wong wrote:

 To round to the nearest 5:

  Divide by 5
  Round to the nearest integer
  Multiply by 5

Modulus by 5
Subtract the result from the original number.



Of course, my way depends on whether you're rounding up or down.
--
S. Keller
UI Engineer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Pkwy.
Anchorage, AK 99508
907.770.6200 ext.220
907.336.6205 (fax)
Email: [EMAIL PROTECTED]
Web: www.healthtvchannel.org


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




Re: [PHP] rounding...sort of

2002-12-28 Thread Jason Wong
On Saturday 28 December 2002 17:49, Peter Lavender wrote:
 Hi everyone,

 I have a nubmer: 4.1 but I only want the whole number 4, even if it's
 4.9, so this rules out using round (Unless I missed a parameter).

 How could I do this.. I'm drawing a blank...

floor()

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Remark of Dr. Baldwin's concerning upstarts: We don't care to eat toadstools
that think they are truffles.
-- Mark Twain, Pudd'nhead Wilson's Calendar
*/


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




Re: [PHP] rounding...sort of

2002-12-28 Thread Justin French
php.net/floor

OR

?
list($w,$d) = split('.','4.9');
echo $w;
?

Justin French



on 28/12/02 8:49 PM, Peter Lavender ([EMAIL PROTECTED]) wrote:

 Hi everyone,
 
 I have a nubmer: 4.1 but I only want the whole number 4, even if it's
 4.9, so this rules out using round (Unless I missed a parameter).
 
 How could I do this.. I'm drawing a blank...
 
 Pete
 
 
 


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




Re: [PHP] rounding...sort of

2002-12-28 Thread Rasmus Lerdorf
Use explode() please

On Sun, 29 Dec 2002, Justin French wrote:

 php.net/floor

 OR

 ?
 list($w,$d) = split('.','4.9');
 echo $w;
 ?

 Justin French



 on 28/12/02 8:49 PM, Peter Lavender ([EMAIL PROTECTED]) wrote:

  Hi everyone,
 
  I have a nubmer: 4.1 but I only want the whole number 4, even if it's
  4.9, so this rules out using round (Unless I missed a parameter).
 
  How could I do this.. I'm drawing a blank...
 
  Pete
 
 
 


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



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




Re: [PHP] rounding a number

2002-06-24 Thread George Whiffen

Jason Wong wrote:

 On Monday 24 June 2002 11:34, Phil Schwarzmann wrote:
  I want to round a number to the nearest decimal place...
 
  if the number is 4.623, I want it to display 4.6
  if the number is 2.36, I want it to display 2.7

 You don't really mean 2.36 -- 2.7 ??

  Is there a function that does this?  round(), ceil(), floor() don't do
  this and I've checked through all the math functions in my handy-dandy
  PHP Functions reference book.

 round() seems to work. What's the problem you're having?


It's worth noting that round doesn't always work e.g.

try round(0.35,1)




 --
 Jason Wong - Gremlins Associates - www.gremlins.com.hk
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *

 /*
 That's no moon...
 -- Obi-wan Kenobi
 */


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




Re: [PHP] rounding a number

2002-06-24 Thread Jim lucas

seems to work fine for me.
what are your results when you do this?  mine are 0.4  and this is what is
should be. if it were .349 it would round down. isn't this how it should
work?   What were your results?

Jim Lucas
- Original Message -
From: George Whiffen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, June 24, 2002 2:36 AM
Subject: Re: [PHP] rounding a number


 Jason Wong wrote:

  On Monday 24 June 2002 11:34, Phil Schwarzmann wrote:
   I want to round a number to the nearest decimal place...
  
   if the number is 4.623, I want it to display 4.6
   if the number is 2.36, I want it to display 2.7
 
  You don't really mean 2.36 -- 2.7 ??
 
   Is there a function that does this?  round(), ceil(), floor() don't do
   this and I've checked through all the math functions in my handy-dandy
   PHP Functions reference book.
 
  round() seems to work. What's the problem you're having?
 

 It's worth noting that round doesn't always work e.g.

 try round(0.35,1)



 
  --
  Jason Wong - Gremlins Associates - www.gremlins.com.hk
  Open Source Software Systems Integrators
  * Web Design  Hosting * Internet  Intranet Applications Development *
 
  /*
  That's no moon...
  -- Obi-wan Kenobi
  */


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




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




Re: [PHP] rounding a number

2002-06-24 Thread Jason Wong

On Tuesday 25 June 2002 02:16, Jim lucas wrote:
 seems to work fine for me.
 what are your results when you do this?  mine are 0.4  and this is what is
 should be. if it were .349 it would round down. isn't this how it should
 work?   What were your results?

  try round(0.35,1)

I get 0.3 on php 4.0.6.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Elegance and truth are inversely related.
-- Becker's Razor
*/


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




RE: [PHP] rounding a number

2002-06-23 Thread Martin Towell

according to the pdf version of the manual I have, round() is what you need

float round(float val[, int precision])

have another look that the man page

-Original Message-
From: Phil Schwarzmann [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 24, 2002 1:35 PM
To: [EMAIL PROTECTED]
Subject: [PHP] rounding a number


I want to round a number to the nearest decimal place...

if the number is 4.623, I want it to display 4.6 
if the number is 2.36, I want it to display 2.7

Is there a function that does this?  round(), ceil(), floor() don't do
this and I've checked through all the math functions in my handy-dandy
PHP Functions reference book.

Thanks for your help!!!

Or..if it's too hard to do that, I could just use a function that
chops off the end of some decimals, like...

if the number is 2.343234, I want just 2.3
or if the number is 2.545434534534534534, I want just 2.5

Thanks!!

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




RE: [PHP] rounding a number

2002-06-23 Thread Jason Soza

I think what you're looking for is number_format() - you can set decimal
places with it and used in combo with round(), ceil(), and/or floor(), you
should be able to achieved the desired result.

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

HTH,

Jason Soza

-Original Message-
From: Phil Schwarzmann [mailto:[EMAIL PROTECTED]]
Sent: Sunday, June 23, 2002 7:35 PM
To: [EMAIL PROTECTED]
Subject: [PHP] rounding a number


I want to round a number to the nearest decimal place...

if the number is 4.623, I want it to display 4.6
if the number is 2.36, I want it to display 2.7

Is there a function that does this?  round(), ceil(), floor() don't do
this and I've checked through all the math functions in my handy-dandy
PHP Functions reference book.

Thanks for your help!!!

Or..if it's too hard to do that, I could just use a function that
chops off the end of some decimals, like...

if the number is 2.343234, I want just 2.3
or if the number is 2.545434534534534534, I want just 2.5

Thanks!!


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




Re: [PHP] rounding a number

2002-06-23 Thread Jason Wong

On Monday 24 June 2002 11:34, Phil Schwarzmann wrote:
 I want to round a number to the nearest decimal place...

 if the number is 4.623, I want it to display 4.6
 if the number is 2.36, I want it to display 2.7

You don't really mean 2.36 -- 2.7 ??

 Is there a function that does this?  round(), ceil(), floor() don't do
 this and I've checked through all the math functions in my handy-dandy
 PHP Functions reference book.

round() seems to work. What's the problem you're having?

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
That's no moon...
-- Obi-wan Kenobi
*/


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




Re: [PHP] Rounding....

2002-02-10 Thread Bogdan Stancescu

I guess that's because nobody knows beforehand which direction the fuzz should
go - should it go a little upwards or a little downwards in order to match
all systems?

Just my two cents.

Bogdan

Matthew Clark wrote:

 Seeing as the mathematically correct way to round numbers is to round down
 to n for n-1=m=n.5 and up to n+1 for n.5mn+1, I wonder why the PHP
 round() function couldn't include a little 'fuzz' to handle the rounding
 problems we encounter due to floating point representation in the hardware?
 It could even be a configurable option - but it would save writing a
 wrapper...

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


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




Re: [PHP] Rounding a number up

2001-09-10 Thread Lance Rochelle

http://www.php.net/manual/en/function.ceil.php

- Original Message - 
From: Brandon Orther [EMAIL PROTECTED]
To: PHP User Group [EMAIL PROTECTED]
Sent: Monday, September 10, 2001 2:19 PM
Subject: [PHP] Rounding a number up


 Is there a way to round a number to the next whole number?
  
 Example: 
  
 Before: 1.86758
  
 After:  2
  
 Thank you,
  
  
 


-- 
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]




RE: [PHP] rounding up

2001-04-27 Thread Joseph Bannon

What is the best seamless way to upgrade/update PHP?

Joseph

-- 
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]




RE: [PHP] rounding up

2001-04-25 Thread Matt Williams

Hi

 
 Is there a PHP command to round up to the nearest integer?

www.php.net/ceil
www.php.net/round

HTH

M@

-- 
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]




RE: [PHP] rounding up

2001-04-25 Thread John Huggins


  Is there a PHP command to round up to the nearest integer?

 www.php.net/ceil
 www.php.net/round


These are the correct functions, but take great care in reading the user
contributed notes in the round function concerning x.5 rounding randomness.
Sometimes this can get you.

If you want to be sure 4.5 always rounds to 5, add a fudge factor smaller
than your precision, but larger than the precision of the computer.

$value = 4.5;
$fudge = 0.001;

round($value) sometimes returns 5
round($value) sometimes returns 4

$fudgedvalue = $value + $fudge;

round($fudgedvalue) = 5

This comes into play often when you do things like split a long list of
items into two columns on your web page and you use PHP (or any language) to
figure out where to end the first column and start the second.

It should be noted that this is not a PHP issue.  It affects any language
which relies on the hardware to compute.

Fun stuff eh?

John


-- 
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]




RE: [PHP] Rounding to strange results

2001-03-06 Thread Johnson, Kirk

Is there a comma in one thousand, e.g., 1,000.00? round() will truncate
everything to the right of a comma.

Kirk

-Original Message-
From: Martin E. Koss [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 06, 2001 7:45 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Rounding to strange results


Hi,
I use a product database for 2 sites, one of which adds sales tax and rounds
to the nearest .10 and on the other site there is no tax and also no
rounding.

I am unable to figure out why a price of 1000.00 is being displayed as 1.00
and any price over 1000 does the same thing. 100.00 works fine, as does all
other prices, this is the same with and without rounding.

Anything I should look for to solve this problem?

Martin.


-- 
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]

-- 
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]




RE: [PHP] Rounding to strange results

2001-03-06 Thread Rick St Jean

You can write  a function that get the %(mod) of 1000 then subtracts it 
from the number.

Rick

At 08:43 AM 3/6/01 -0700, Johnson, Kirk wrote:
Is there a comma in one thousand, e.g., 1,000.00? round() will truncate
everything to the right of a comma.

Kirk

-Original Message-
From: Martin E. Koss [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 06, 2001 7:45 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Rounding to strange results


Hi,
I use a product database for 2 sites, one of which adds sales tax and rounds
to the nearest .10 and on the other site there is no tax and also no
rounding.

I am unable to figure out why a price of 1000.00 is being displayed as 1.00
and any price over 1000 does the same thing. 100.00 works fine, as does all
other prices, this is the same with and without rounding.

Anything I should look for to solve this problem?

Martin.


--
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]

--
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]

##
#  Rick St Jean,
#  [EMAIL PROTECTED]
#  President of Design Shark,
#  http://www.designshark.com/
#  Quick Contact:  http://www.designshark.com/messaging.ihtml
#  Tel: 905-684-2952
##


-- 
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]




Re: [PHP] Rounding a number up if the number is anything more thana whole number

2001-01-17 Thread Ignacio Vazquez-Abrams

On Mon, 17 Jan 2000, Brandon Orther wrote:

 Hello,

 I am doing a math function where I divide one number by another.  I want it
 to give me a whole number though, and if it is anything above a number I
 want it to go to the next one up.

 Example:

 4.0001  would equal 5

 3.98 would equal 4

 11.023 would equal 12


   I hope you understand what I am trying to say.


 Thank you,

 
 Brandon Orther
 WebIntellects Design/Development Manager
 [EMAIL PROTECTED]
 800-994-6364
 www.webintellects.com
 


ceil()

-- 
Ignacio Vazquez-Abrams  [EMAIL PROTECTED]


-- 
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]